Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongodb对列进行计数和分组的查询_Mongodb - Fatal编程技术网

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

mongodb对列进行计数和分组的查询,mongodb,Mongodb,我想查询mongodb数据,检查每天有多少产品收到评论 我可以用SQL查询来表达我的需求 SELECT Product, Date, count(Product) FROM Exported_Data WHERE Category like "Battery" GROUP by Date,Product; 有人能帮我为上面的查询编写mongodb查询吗 我的数据在mogodb中是这样的- /* 1 */ { "_id" : ObjectId("5d80bf6043fdfd6874bc0

我想查询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

根据您的问题检查此项,并在“评论”字段中分组。提供的sql查询在“类别”字段中具有按产品分组、日期和where条件。您的虚拟数据只有两条条件“类别”记录:“电池”。你的预期结果还有别的。你能先核实一下你的问题吗?同时,您还可以尝试以下带有类别条件的查询:db.collection.aggregate([{$match:{“category”:“Battery,,}},{$group:{{u id:{dateTemp:{dateTemp:$Date],productTemp:$Product},numberofPostID:{$sum:1}},{$sort:{$numberofPostID:-1}])No。。不按“注释”分组,我的结果中不需要注释字段。分组依据应先按日期,然后按产品。。就像在SQL中那样。。然而,您的代码帮助我在很少修改的情况下获得了所需的结果。db.getCollection('Exported_Data').aggregate([{$match:{“Category”:“Battery,,}},{$group:{U id:{dateTemp:{dateTemp:$Date,”,productTemp:$Product:“$Product”,categoryTemp:$Category”},numberofPostID:{$sum:1},{$sort:{$numberofPostID:{1}])很高兴我的评论对你有所帮助,如果你能对我的评论投上一票就太好了。干杯:)