【问题标题】:How to implement aggregate in erlang MongoDB driver如何在 erlang MongoDB 驱动程序中实现聚合
【发布时间】:2014-11-17 23:39:03
【问题描述】:

我正在尝试将聚合与 erlang mongodb driver 一起使用。这是我迄今为止尝试过的

mongo_query:command({Db, Conn}, {aggregate,<<"users">>,pipeline, <<"{$group:{_id:\"\", id: {$sum: \"$id\"}} }, {$project:{ _id:0, id: \"$id\"}}">>}, false).

但我收到此错误

** exception error: {bad_command,{errmsg,<<"exception: wrong type for field (pipeline) 2 != 4">>,
                                         code,13111,ok,0.0}}

我在前进时遇到了麻烦,正在寻找任何有关使用 erlang 驱动程序实现聚合的方法的帮助。

为了清楚起见,我正在尝试实现这一点

db.users.aggregate({$group:{_id:"", id: {$sum: "$id"}} }, {$project:{ _id:0, id: "$id"}});

在 MongoDB shell 中工作。

【问题讨论】:

    标签: mongodb erlang


    【解决方案1】:

    如果有人插话,我会听从知道 erlang 的人,但因为没有人知道:我认为您正在为驱动程序期望列表的管道参数提供一个字符串。

    【讨论】:

      【解决方案2】:

      您应该尝试以下方式:
      mongo:command(Connection, {aggregate,&lt;&lt;"users"&gt;&gt;,pipeline, [{'$group',{'_id', id, {'$sum', '$id'}}}, {'$project',{'_id',0, id, '$id'}}]}).

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-03
        • 1970-01-01
        • 1970-01-01
        • 2020-06-21
        • 2020-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多