2
我正在展示一個mongodb集合文檔結構的例子。我也顯示了我的預期結果,同時進行查詢,我已經顯示。如何返回mongodb內部數組中的部分數組匹配?
文檔結構::
{
_id : "132423423",
name : "hi_code",
my_entries : [
{
e_id : "12345",
e_name : "f1",
e_posted : "2010-05-01",
},
{
e_id : "12346",
e_name : "f2",
e_posted : "2010-06-01",
},
{
e_id : "12346",
e_name : "f3",
e_posted : "2010-03-02",
}
]
}
查詢結構::
db.myCollection.find({ my_entries : { $elemMatch : { e_posted : "2010-06-01",
e_name : "f2" } } })
預期結果::
{
_id : "132423423",
name : "hi_code",
my_entries : [
{
e_id : "12346",
e_name : "f2",
e_posted : "2010-06-01",
}
]
}
我並不想用地圖降低,是因爲我我正在處理大型數據庫,這會使其性能變慢,只想通過find查詢來實現。
我可以使用任何其他技巧解決此問題,而無需mapreduce在mongodb版本2.0.4中使用。 –
您可以在應用程序端執行此操作 - 匹配文檔,然後在檢索後取出所需內容。 –
您只能通過$ slice運算符獲取數組的子集,但需要知道數組元素的位置。 –