mongodb - Is Mongo aggregation with a date range broken? -
i have collection of documents string field "action" , "receivedtimestamp" date field, values of march , april 2016. i'm trying count how many there of each action in date range.
when run this:
db.getcollection('foo').aggregate([ {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 68 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$gte": new date("2016-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 68 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$gte": new date("2017-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 68 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$lte": new date("2017-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 0 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$lte": new date("2016-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 0 results.
so i'm starting think mongo aggregation date range broken. wrong?
solved switching isodate:
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$gte": new isodate("2016-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 68 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$gte": new isodate("2017-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 0 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$lte": new isodate("2016-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 0 results.
when run this:
db.getcollection('foo').aggregate([ {"$match": {"receivedtimestamp": {"$lte": new isodate("2017-01-01")}}}, {"$group": {"_id": "$action", "count": {"$sum": 1}}} ])
i 68 results.
this behavior expect see. i'm not aware of documentation of requirement use isodate in context.
Comments
Post a Comment