0
下面的json表示我的集合的文檔結構。查詢排除MongoDB中的數組列
{
"_id" : ObjectId("591a653c366df19100ed0fbc"),
"sno" : 1,
"chapterName" : "chapter 1: Express JS",
"overView" : "Overview of Express JS",
"sections" : [
{
"title" : "The Node.js philosophy",
"subSections" : [
{
"sno" : 1,
"title" : "Small core 1",
"content" : "The Node.js core itself has its foundations 1"
},
{
"sno" : 2,
"title" : "Small core 2",
"content" : "The Node.js core itself has its foundations 2"
}
]
},
{
"title" : "The Node.js philosophy 2",
"subSections" : [
{
"sno" : 1,
"title" : "Small core 1",
"content" : "The Node.js core itself has its foundations 1"
},
{
"sno" : 2,
"title" : "Small core 2",
"content" : "The Node.js core itself has its foundations 2"
}
]
}
]
}
我想編寫一個查詢將在下文中提到的方式返回數據的所有記錄(不包括「內容」)
{
"_id" : ObjectId("591a653c366df19100ed0fbc"),
"sno" : 1,
"chapterName" : "chapter 1: Express JS",
"overView" : "Overview of Express JS",
"sections" : [
{
"title" : "The Node.js philosophy",
"subSections" : [
{
"sno" : 1,
"title" : "Small core 1"
},
{
"sno" : 2,
"title" : "Small core 2"
}
]
},
{
"title" : "The Node.js philosophy 2",
"subSections" : [
{
"sno" : 1,
"title" : "Small core 1"
},
{
"sno" : 2,
"title" : "Small core 2"
}
]
}
]
}
不知道如何才達到的?
這是可能的。但是你真的不應該嵌套數組,因爲它可以被更新的限制。所以儘管可能,但這也不是微不足道的,如果你稍微扁平化文檔結構,它將更加簡單和高效。考慮單個數組中項目的屬性,而不是將一個數組嵌套到另一個數組中。 –