seasons.jsonMongoDB中找到查詢
{
"_id" : "unique_1",
"spring" : [{
"fruit" : "mango",
"person_id" : [101.0, 102.0, 103.0, 104.0]
}, {
"fruit" : "banana",
"person_id" : [151.0, 152.0, 153.0, 154.0]
}],
"summer" : [{
"fruit" : "mango",
"person_id" : [201.0, 202.0, 203.0, 204.0]
}, {
"fruit" : "banana",
"person_id" : [251.0, 252.0, 253.0, 254.0]
}],
"fall" : [{
"fruit" : "mango",
"person_id" : [301.0, 302.0, 303.0, 304.0]
}, {
"fruit" : "banana",
"person_id" : [351.0, 352.0, 353.0, 354.0]
}],
"winter" : [{
"fruit" : "mango",
"person_id" : [401.0, 402.0, 403.0]
}, {
"fruit" : "banana",
"person_id" : [451.0, 452.0, 453.0]
}]
}
/* 2 */
{
"_id" : "unique_2",
"spring" : [{
"fruit" : "banana",
"person_id" : [151.0, 152.0, 153.0, 154.0]
}],
"summer" : [{
"fruit" : "mango",
"person_id" : [201.0, 202.0, 203.0, 204.0]
}, {
"fruit" : "banana",
"person_id" : [251.0, 252.0, 253.0, 254.0]
}],
"fall" : [{
"fruit" : "banana",
"person_id" : [351.0, 352.0, 353.0, 354.0]
}],
"winter" : [{
"fruit" : "mango",
"person_id" : [401.0, 402.0, 403.0]
}, {
"fruit" : "banana",
"person_id" : [451.0, 452.0, 453.0]
}]
}
以上JSON記錄顯示哪個季節哪個人吃了芒果和具有食用香蕉。
這是我想要找什麼: 當我知道_id預先記錄的(主鍵)或記錄發現之前 -
1)全部爲person_id從101 - 350中爲person_id是獨特 2)person_id只吃芒果 3)吃水果芒果或香蕉記錄的人總數。
請出示你的努力(即代碼)第一。 –
我在特定的fruit-db.season.find({「spring.person_id」:{「$ elemMatch」:{「$ gt」:101,「$ lt」:104}}}中找出了person_id的範圍。 ); – joshi