Count only considers date and not time when aggregating in mongodb -



Count only considers date and not time when aggregating in mongodb -

related question aggregate count has been answered below

count , aggregate in mongodb

query is

db.sg_searchaudit.aggregate([ {"$unwind": "$log" }, {"$match": {"log.ts": {"$gte": new date("2014-09-01"), "$lte": new date("2014-11-04")}}}, {"$group": {"_id": "$_id","count": { "$sum": 1 }}}, {"$sort": {"count":1}}, {"$limit": 50}])

when check above query single keyword :-

db.sg_searchaudit.aggregate([ {"$match":{"_id": "mongo" ,"log.ts": {"$gte": new date("2014-09-01t00:00:00.00z"), "$lte": new date("2014-11-04t00:00:00.00z")}}}, {"$unwind": "$log" }, {"$match": {"log.ts": {"$gte": new date("2014-09-01t00:00:00.00z"), "$lte": new date("2014-11-04t00:00:00.00z")}}}, {"$group": {"_id": "$_id","count": { "$sum": 1 }}}, {"$sort": {"count":-1}}, {"$limit": 50}])

tha when got know aggregates each date rather aggregating on timestamp.

so above query "mongo" returns me 2 instead of 4 below data.

{ "_id" : "mongo", "log" : [ { "ts" : isodate("2011-02-10t01:20:49z"), "visitorid" : "25850661" }, { "ts" : isodate("2014-11-01t14:35:05z"), "visitorid" : numberlong(278571823) }, { "ts" : isodate("2014-11-01t14:37:56z"), "visitorid" : numberlong(0) }, { "ts" : isodate("2014-11-04t06:23:48z"), "visitorid" : numberlong(225200092) }, { "ts" : isodate("2014-11-04t06:25:44z"), "visitorid" : numberlong(225200092) } ], "uts" : isodate("2014-11-04t06:25:43.740z") }

any suggestions ?

mongodb mongodb-query aggregation-framework

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -