我需要在laravel工作框架下面的查詢結果(使用jenssegers庫)
如何在MongoDB中的laravel框架執行總
db.product.aggregate({ $group : {_id : "$catid", total : { $sum : 1}}},
{$sort:{total:-1}});
我試圖做到這一點像這樣
return DB::connection($this - > connection)- >
collection($this - > collection) - > aggregate(
'{ $group : {_id : "$catid", total : { $sum : 1 }}},{$sort:{total:-1}}'');
但它給出錯誤,如「ErrorException未定義索引:聚合」需要知道如何使用mongodb「db.collection.aggregate」
我收藏的文件是這樣的
{
"_id": ObjectId("5369d68611fe14ddc5f59ff9"),
"sku": 123456,
"productid": 1,
"name": "name1",
"catid": 1
}
如果可能的話顯示你的數據庫結構的問題 – Mayuri
嗨米婭,我已經包括我的收藏文件,以獲得結構的想法謝謝你看着這個。 –