我需要在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)