0
查詢未示出:的MongoDB - 場骨料
db.environments.aggregate(
[{$match:{customer:"CustomerName"}},
{$group:{_id:{environment: "$environment",
cpu_oversubscription:"$cpu_oversubscription",
memory_oversubscription:"$memory_oversubscription"}}} ])
當運行該查詢僅環境和CPU_oversubcription字段被示出,未示出的存儲器領域。
這是輸出我得到:
[{"_id":{"environment":"V&B","cpu_oversubscription":1}}
當我運行db.environments.find()
我看到所有的領域
[{"_id":{"environment":"V&B","cpu_oversubscription":1,"memory_oversubscription":1,"customer":"CustomerName"}}
什麼是錯我的查詢?
編輯:精確查詢
Environment.aggregate([{$match:{customer:req.query.customer}},{$group:{_id:{environment: "$environment",cpu_oversubscription:"$cpu_oversubscription",memory_oversubscription:"$memory_oversubscription",}}} ])
查詢的精確結果
{ "_id" : { "environment" : "1", "cpu_oversubscription" : 1 } }
{ "_id" : { "environment" : "2", "cpu_oversubscription" : 4 } }
{ "_id" : { "environment" : "3", "cpu_oversubscription" : 4 } }
{ "_id" : { "environment" : "4", "cpu_oversubscription" : 4 } }
{ "_id" : { "environment" : "5", "cpu_oversubscription" : 4 } }
{ "_id" : { "environment" : "6", "cpu_oversubscription" : 1 } }
{ "_id" : { "environment" : "7", "cpu_oversubscription" : 1 } }
{ "_id" : { "environment" : "8", "cpu_oversubscription" : 1 } }
{ "_id" : { "environment" : "9", "cpu_oversubscription" : 4 } }
{ "_id" : { "environment" : "10", "cpu_oversubscription" : 4 } }
db.environments.find的精確結果()(僅第一結果)
{ "_id" : ObjectId("560a5139b56a71ea60890201"), "customer" : "CustomerName", "environment" : "1", "memory_oversubcription" : 1, "cpu_oversubscription" : 1 }
這裏你的數據樣本是否正確?一切都在'_id'之下,並且你的聚合中沒有任何字段(看起來基於問題,然後由我自己回答)帶有'_id'前綴,如同在{{$ group「:{」_id「:{」environment 「:」$ _id.environment「}}}'。主要指出,這不是前面問題中提出的結構。所以我認爲你在這篇文章中犯了一個錯誤。 –
該查詢是正確的,但我沒有看到它的重點,因爲你最終沒有對任何東西進行分組。如果你不使用任何這些操作符:http://docs.mongodb.org/manual/reference/operator/aggregation/group/#accumulator-operator,一個簡單的查找可以做我認爲的詭計。 –
爲什麼顯示cpu_oversubcription,但memory_oversubscription不? – CMS