1
school object :{
"id":"school1"
"adress":"aaaaa"
"studentInfo":{
"details" : [
{
"class" : "a",
"studentId" : "dan",
"subject" : "math",
},
{
"class" : "b",
"studentId" : "ron",
"subject" : "math",
}
]
}
}
我有一個問題,從詳細數組中獲取特定對象的問題。 我期望的結果是由studentId發現:我需要通過在嵌套在對象中的數組中的查找對象的幫助
{
"class" : "a",
"studentId" : "dan",
"subject" : "math",
}
我想:提前
db.getCollection('schools').find(
{'name':'school1'},
{'studentInfo.details':{$elemMatch:{'studentId':'dan'} } }
)
感謝
school1是'id'屬性的值。你爲什麼用'名字'搜索? – Mikhail