假設我有這種文檔結構,屬性字段將是嵌入文檔 ,並且我已經爲屬性.key和attributes.value編入索引如何從嵌入文檔的鍵值類型獲得確切文檔結果
1-------------------------------------------------------------------------------------
{
"_id" : ObjectId("5191d8e5d00560402e000001"),
"attributes" : [
{ "key" : "pobox","value" : "QaKUWo" },
{ "key" : "city", "value" : "CBDRip" },
{ "key" : "address","value" : "zmycAa" } ],
"email" : "[email protected]",
"firstname" : "FWAUdl_2"
}
2-------------------------------------------------------------------------------------
{
"_id" : ObjectId("5191d8e7d00560402e000055"),
"attributes" : [
{ "key" : "pobox", "value" : "sNFriy" },
{ "key" : "city", "value" : "JPdVrI" },
{ "key" : "address", "value" : "phOluW" } ],
"email" : "[email protected]",
"firstname" : "hqYNWH_86"
}
我的問題是,如何查詢僅基於屬性字段時得到確切的文件,
db.app.find({ attributes.key:address , attributes.value:/.*uw.*/i })
查詢結果並不如我所料,這應導致只有第2文件只是沒了第一次文件。 我知道我在attributes.value上設置了正則表達式,我期待它只檢查具有地址值的attributes.key。
如果我要過濾的另一個關鍵,例如像什麼,
db.app.find({ attributes.key:address , attributes.value:/.*uw.*/i , attributes.key:city , attributes.value:/.*ri.*/i })
任何意見將是有益的人。 Thx。
是的,我以爲我也這麼做過,猜猜這不是一個高性能的選項,但它的工作原理,thx btw :) – 2013-05-15 12:21:27