MongoDB count aggregate per month -
is there way total number of documents in mongodb database months (for example, can display chart showing evolution of number of users) in single request? or should request each month individually?
i don't want see number of users created in month total (this month + previous months).
each document in collection has field representing date created. total number of documents in mongodb database months, use range query query documents value created_on greater date representing start of month, , less date representing end.
assume start date 'start' , end date 'end'. query be,
db.users.count({created_on: {$gte: start, $lt: end}});
here nice explanation relevant topic. http://cookbook.mongodb.org/patterns/date_range/
refer answers in thread also. find objects between 2 dates mongodb
Comments
Post a Comment