小编Luc*_*wan的帖子

如何在laravel框架中的mongodb中执行聚合

我需要在laravel框架工作中获得以下查询的结果(使用jenssegers库)

db.product.aggregate({ $group : {_id : "$catid", total : { $sum : 1}}},
                                {$sort:{total:-1}});
Run Code Online (Sandbox Code Playgroud)

我试着这样做

return DB::connection($this - > connection)- > 
          collection($this - > collection) - > aggregate(
        '{ $group : {_id : "$catid", total : { $sum : 1 }}},{$sort:{total:-1}}'');
Run Code Online (Sandbox Code Playgroud)

但它给出的错误如"ErrorException Undefined index:aggregate"需要知道如何使用mongodb"db.collection.aggregate"

我收藏的文件是这样的

  {
     "_id": ObjectId("5369d68611fe14ddc5f59ff9"),
     "sku": 123456,
     "productid": 1,
     "name": "name1",
     "catid": 1
 }
Run Code Online (Sandbox Code Playgroud)

mongodb laravel-4

6
推荐指数
1
解决办法
4308
查看次数

标签 统计

laravel-4 ×1

mongodb ×1