1

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:

  1. Isn't this very verbose?
  2. Is this correct usage?
  3. Do i have to rethink the structure of my document?
4
  • At first I would simplify names, to get query ie. chapters.articles.headings.title. in short, you have redundand field names.
    – user133408
    Commented Feb 27, 2014 at 16:22
  • good thinking, thx... i will change that soon...
    – kevinius
    Commented Feb 27, 2014 at 16:24
  • Keep in mind that you are really not asking a programming question here. But are asking for opinions or otherwise making commentary. Perhaps try an re-phrase in the form of a specific question.
    – Neil Lunn
    Commented Feb 27, 2014 at 17:00
  • Hi, thx for you concern. I'm not asking for opinions, i'm asking for best practices. I do believe this to be a real programming question.
    – kevinius
    Commented Feb 27, 2014 at 17:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.