-3
Hello all i have different document containing "category" field i have to get result from aggregation query to find number of document in each category and find result in array which sould contain {_id and num } field;
{
"_id": NumberInt(23),
"title": "WiredTiger T-shirt",
"slogan": "Unleash the tiger",
"description": "Crafted from ultra-soft combed cotton, this essential t-shirt features sporty contrast tipping and MongoDB's signature leaf.",
"stars": NumberInt(0),
"category": "Apparel",
"img_url": "/img/products/wt-shirt.jpg",
"price": 22
}
{
"_id": NumberInt(22),
"title": "Water Bottle",
"slogan": "Glass water bottle",
"description": "High quality glass bottle provides a healthier way to drink. Silicone sleeve provides a good grip, a see-through window, and protects the glass vesse [...]",
"stars": NumberInt(0),
"category": "Kitchen",
"img_url": "/img/products/water-bottle.jpg",
"price": 23
}
我有很多這樣的文檔。我使用了下面的查詢: -mongodb聚合查詢無法創建
db.collectionname.find({category:「categoryname」},{_ id:1})。count(); 但在這個階段我只會得到一個類別的數據。
這個問題並沒有表現出任何的研究工作.... –
你好亞歷克斯我在MongoDB中新並抱歉沒有提及我已經嘗試了db.collectionname.find({category:「categoryname」},{_ id:1})。count();但在這個階段,我只會得到一個類別的數據 –
我怎麼能得到想要的結果?如果你知道請幫助我。 –