我的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
}
要.find()深度嵌入字段“headingTitle”的值,我必须使用此查询:
/*
db.bookcollections.findOne({"bookChapters.chapterArticles.articleHeadings.headingTitle":"headingTitle"}, {"bookChapters.chapterArticles.articleHeadings.headingTitle":1}).bookChapters[0].chapterArticles[0].articleHeadings[0].headingTitle
*/
关于最佳做法: