2017-02-09 59 views
0

我試圖從MongoDB的彙總數據每個文件名每個版本,其中平臺是贏得使用JavaScript MongoDB的驅動器,用於聚集

我的數據格式如下

[ 
{ "_id" : { "platform" : "mac", "filename" : "f1.json", "version" : "1.4.14" }, "avgSecs" : 15 }, 
{ "_id" : { "platform" : "win", "filename" : "f2.json", "version" : "3000.0.0_developer" }, "avgSecs" : 1217 }, 
{ "_id" : { "platform" : "win", "filename" : "f3.json", "version" : "1.4.14" }, "avgSecs" : 1711 }, 
{ "_id" : { "platform" : "win", "filename" : "f3.json", "version" : "3000.0.0_developer" }, "avgSecs" : 1191 } 
] 

我的代碼如下

[ {$sort:{filename:1}},{$match:{platform:"win"}},{ $group:{ _id: {filename:"$filename", version:"$version"}, avgSecs: {$avg:"$int_secs"} } }] 

其發送使用JS的API如下

至MongoDB的

但我沒有得到解析和聚合數據,但完整的數據是從數據庫。

我檢查了相同的聚合查詢適用於mongodb shell。我不確定JS api有什麼問題。我是否正確地使用它

回答

1

好的發現它。

AggQuery在預期數組對象時以字符串形式發送。 使對象數組和現在的結果如預期。