Quantcast
Channel: group by dates in mongodb - Stack Overflow
Browsing latest articles
Browse All 11 View Live

Answer by anshuman burmman for group by dates in mongodb

To fetch data group by date in mongodb db.getCollection('supportIssuesChat').aggregate([ { $group : { _id :{ $dateToString: { format: "%Y-%m-%d", date: "$createdAt"} }, list: { $push: "$$ROOT" },...

View Article



Answer by mhalttu for group by dates in mongodb

There are already many answers to this question, but I wasn't happy with any of them. MongoDB has improved over the years, and there are now easier ways to do it. The answer by Jonas Tomanga gets it...

View Article

Answer by Jonas Tomanga for group by dates in mongodb

This can help return new Promise(function(resolve, reject) { db.doc.aggregate( [ { $match: {} }, { $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date" } }, count: { $sum: 1 } } }, {...

View Article

Answer by egvo for group by dates in mongodb

Of course, that is a good solution. Aside from that you can group dates by days as strings (as that answer propose) or you can get the beginning of dates by projecting date field (in aggregation) like...

View Article

Answer by Blakes Seven for group by dates in mongodb

If You want a Date oject returned directly Then instead of applying the Date Aggregation Operators, instead apply "Date Math" to round the date object. This can often be desirable as all drivers...

View Article


Answer by Old Pro for group by dates in mongodb

New answer using Mongo aggregation framework After this question was asked and answered, 10gen released Mongodb version 2.2 with an aggregation framework, which is now the better way to do this sort of...

View Article

Answer by phnessu4 for group by dates in mongodb

thanks for @mindthief, your answer help solve my problem today. The function below can group by day a little more easier, hope can help the others. /** * group by day * @param query document...

View Article

Answer by golja for group by dates in mongodb

Another late answer, but still. So if you wanna do it in only one iteration and get the number of clicks grouped by date and topic you can use the following code: db.coll.group( { $keyf : function(doc)...

View Article


Answer by mindthief for group by dates in mongodb

Late answer, but for the record (for anyone else that comes to this page): You'll need to use the 'keyf' argument instead of 'key', since your key is actually going to be a function of the date on the...

View Article


Answer by enricog for group by dates in mongodb

Haven't worked that much with MongoDB yet, so I am not completely sure. But aren't you able to use full Javascript? So you could parse your date with Javascript Date class, create your date for the day...

View Article

group by dates in mongodb

I am working on a project in which I am tracking number of clicks on a topic. I am using mongodb and I have to group number of click by date( i want to group data for 15 days). I am having data store...

View Article
Browsing latest articles
Browse All 11 View Live




Latest Images