我正在使用官方的mongo scala驱动程序:
http://mongodb.github.io/mongo-scala-driver/
.
我想做如下查询:
db.test.aggregate([{"$group" : {_id:{name:"$name",details:"$details.id"}, count:{$sum:1}}}, {$sort:{"count":-1}} ])
所以在scala代码中我要做的是:
collectionDoc.aggregate(List(
group(Document("name" -> "$name", "details" -> "$details.id"), Accumulators.sum("count", "1")),
)).toFuture()
但在所有结果中我看到:
(count,BsonInt32{value=0}))
从Mongo驱动程序日志中,我看到它发送:
{
"aggregate": "test",
"pipeline": [
{
"$group": {
"_id": {
"name": "$name",
"details": "$details.id"
},
"count": {
"$sum": "1"
}
}
}
],
"cursor": {
"batchSize": 2147483647
},
"$db": "my-db",
"$readPreference": {
"mode": "primaryPreferred"
}
}
如果我在Mongo中执行此查询,它会对这些记录进行良好计数。
知道怎么解决这个问题吗?
谢谢!