mongodb查询以对列进行计数和分组

时间:2019-09-18 07:21:30

标签: mongodb

我想查询mongodb数据以检查每天有多少产品收到评论。

我可以在SQL查询中表达我的要求。

SELECT Product, Date, count(Product) FROM Exported_Data WHERE Category like "Battery" GROUP by Date,Product;

任何人都可以帮助我为上述查询编写mongodb查询。

我的数据在mogodb中看起来像这样

/* 1 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc057b"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/17/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "Samsung galaxy M30s will India only exclusive model and made in India. maybe it will be extend to Sri Lanka. buying not impossible in South East Asia and Europa. We are sad. "
}

/* 2 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc057c"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/17/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "ema99, 16 Sep 2019hope it is not meant for India only, Uganda also needs thisSouth Africa as well. India I not the only third world country, we need good low cost phones too..."
}

/* 3 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc057d"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/17/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "Battery,",
    "Comment" : "Again too large, not 5G, while when next year the supporting transmitters will be ready for 5G testing has already taken place in different cities, the battery is still not interchangeable, so it does not have to be watertight for most. I don't dive with it and I'm not in the rain either. I think more people can also give their opinion better, Samsung needs to listen to the people more and collect these opinions."
}

/* 4 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc057e"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/16/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "Anonymous, 15 Sep 2019Not going to Indonesia, M30s wlll India only exclusive model, maybe it will be extend to Sti L... moreLet see it bro, because A30s & A50s have been released in indonesia a month ago, Hopefully M30s too"
}

/* 5 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc057f"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/16/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "hope it is not meant for India only, Uganda also needs this"
}

/* 6 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0580"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/16/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "Anonymous, 15 Sep 2019Not going to Indonesia, M30s wlll India only exclusive model, maybe it will be extend to Sti L... moreIt will come to Indonesia Malaysia etc soon but price will be different compare to India. "
}

/* 7 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0581"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/16/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "Screen,Battery,",
    "Comment" : "Adexaaz92, 15 Sep 2019Samsung m30s is excellent,the battery is awesome infact the specs is mind blowing but the pric... moreHi sir.... does it have gorilla screen protection?"
}

/* 8 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0582"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/16/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "Screen,",
    "Comment" : "Screen protection is there?"
}

/* 9 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0583"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/15/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "Anonymous, 12 Sep 201916K is the price and it's a much better value proposition when compared to chinese brands like... moreDon't worry ,it won't cost less than 16,999 . You can take this as official price."
}

/* 10 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0584"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/15/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "Battery,",
    "Comment" : "Samsung m30s is excellent,the battery is awesome infact the specs is mind blowing but the price needs some adjustment to make more sales, so samsung pls keep it up,thank you. "
}

/* 11 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0585"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/15/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "This phone is expected to replace A50, hence it will be priced between the current M30 and A50. Because the A50s price is more than the existing A50 series..."
}

/* 12 */
{
    "_id" : ObjectId("5d80bf6043fdfd6874bc0586"),
    "Product" : "Samsung Galaxy M30s",
    "Date" : "09/15/2019",
    "Thread" : "https://www.gsmarena.com/samsung_galaxy_m30s-reviews-9818p1.php",
    "Category" : "other",
    "Comment" : "Sandeep, 15 Sep 2019M30 s have gorilla glass ? I think they should skip on that and just go for in house glass protection because they are just as potent, if not more, than the proprietary protection available in market and it will help then save costs and pass it on to customers"
}

预期结果如下-

三星Galaxy M30s 9/3/2019电池3 三星Galaxy M30s 9/4/2019电池5 三星Galaxy M30s 9/5/2019电池2 三星Galaxy M30s 9/6/2019电池1

0 个答案:

没有答案