{
"_id" : "toy_in_en_L02B",
"modelCode" : "L02B",
"path" : "/toy/in/en",
"dataPath" : "/toy/in/en/L02B",
"basicModelInformation" : {
"name" : "News",
"startingPrice" : "1234.0"
},
"grades" : {
"grades" : [
{
"key" : "LVL001",
"dataPath" : "/toy/in/en/L02B",
"name" : "XE P",
"price" : "1234.0"
},
{
"key" : "LVL002",
"dataPath" : "/toy/in/en/L02B",
"name" : "XE P",
"price" : "1234.0"
},
{
"key" : "LVL003",
"dataPath" : "/toy/in/en/L02B",
"name" : "XE P",
"price" : "1234.0"
},
{
"key" : "LVL004",
"dataPath" : "/toy/in/en/L02B",
"name" : "XE P",
"price" : "1234.0"
}
]
}
}
一個MongoDB的文件現在我想找回一個完整的文件僅具有一個檔次爲LVL001。但是,當我這樣查詢這個
db.getCollection('models').find({$and: [{"dataPath" : "/nissan/in/en/L02B" }, {"grades.grades" : {$elemMatch: {"key":"LVL002"}}}]})
我得到所有的成績。
我已經檢查了線程Retrieve Queried Element但沒有得到它。
我的代碼使用Spring @Query。任何json查詢參數也是有用的。
參考https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection – pynewbie
這是我檢查的第一個線程。這在我的問題中已經提到。但是我沒有得到理想的結果。我想在我的查詢結果中只有一個元素等級(請求)。 – Ashish
你的mongo服務器版本是什麼? – Veeram