[英]How to implement aggregate in erlang MongoDB driver
I am trying to use aggregate with the erlang mongodb driver .我正在尝试将聚合与erlang mongodb 驱动程序一起使用。 This is what I have tried so far这是我迄今为止尝试过的
mongo_query:command({Db, Conn}, {aggregate,<<"users">>,pipeline, <<"{$group:{_id:\"\", id: {$sum: \"$id\"}} }, {$project:{ _id:0, id: \"$id\"}}">>}, false).
but I recieve this error但我收到这个错误
** exception error: {bad_command,{errmsg,<<"exception: wrong type for field (pipeline) 2 != 4">>,
code,13111,ok,0.0}}
I am having trouble moving forward and am looking for any help with a way to implement aggregate with the erlang driver.我在前进时遇到了麻烦,正在寻找任何帮助来实现使用 erlang 驱动程序进行聚合的方法。
Just to be clear I am trying to implement this为了清楚起见,我正在尝试实现这一点
db.users.aggregate({$group:{_id:"", id: {$sum: "$id"}} }, {$project:{ _id:0, id: "$id"}}); db.users.aggregate({$group:{_id:"", id: {$sum: "$id"}} }, {$project:{ _id:0, id: "$id"}});
which works in the MongoDB shell.它在 MongoDB shell 中工作。
如果有人插话,我会听从知道 erlang 的人的意见,但由于没有人:我认为您正在为驱动程序期望列表的管道参数提供一个字符串。
你应该尝试这样的事情:
mongo:command(Connection, {aggregate,<<"users">>,pipeline, [{'$group',{'_id', id, {'$sum', '$id'}}}, {'$project',{'_id',0, id, '$id'}}]}).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.