0
請告訴我,我在這裏缺少:怎樣才能返回數組中只有匹配成員
這是我創建的文檔:
fatDoc = {
name: "Babak",
personID : 555,
email : "[email protected]",
music : ["pink floyd", "muse", "garfunkel"],
food : ["free food", "yummy food", "mom food"],
addresses:
[ { type: "home",
street: "123 Main",
state: "NY",
city: "brooklyn"
},
{ type: "vacation",
street: "456 sunshine",
state: "CA",
city: "SanFran"
}
]
}
,這是我上運行的查詢:
db.coolkids.find({"addresses.type" : "home"}, {addresses:1}).pretty()
問題1:爲什麼這兩個地址都作爲查詢返回? 問題2:如何將其更改爲僅返回第一個文檔是「主」地址而不是數組的第二個成員?
非常感謝Asya,書籍作者,工程師和MongoDB架構師都在這裏,幫助我們進一步瞭解MongoDB。 – Bohn