I have this document in my mongoDB:
/* 0 */
{
"bookTitle" : "HTML",
"bookOrder" : 500,
"_id" : ObjectId("530dea1d2dbf280000533b60"),
"bookChapters" : [
{
"chapterTitle" : "chapterTitle",
"chapterIntro" : "ChapterIntro",
"chapterOrder" : 500,
"_id" : ObjectId("530dea1d2dbf280000533b61"),
"chapterArticles" : [
{
"articleTitle" : "articleTitle",
"articleIntro" : "articleIntro",
"articleOrder" : 500,
"_id" : ObjectId("530dea1d2dbf280000533b62"),
"articleHeadings" : [
{
"headingTitle" : "headingTitle",
"headingOrder" : 500,
"_id" : ObjectId("530dea1d2dbf280000533b63")
}
]
}
]
}
],
"__v" : 0
}
To .find() the value of the deeply embedded field "headingTitle" i have to use this query:
/*
db.bookcollections.findOne({"bookChapters.chapterArticles.articleHeadings.headingTitle":"headingTitle"}, {"bookChapters.chapterArticles.articleHeadings.headingTitle":1}).bookChapters[0].chapterArticles[0].articleHeadings[0].headingTitle
*/
Concerning best practices:
- Isn't this very verbose?
- Is this correct usage?
- Do i have to rethink the structure of my document?
chapters.articles.headings.title
. in short, you have redundand field names.