I am adding a date value to the MongoDB collection as part of a map reduction call:
day = Date.UTC(this.time.getFullYear(), this.time.getMonth(), this.time.getDate());
emit({ user : this.user, day : day }, { count : 1 });
When I later request this collection in the Mongo shell, I see:
{ "_id" : { "user" : "assaf", "day" : 1331769600000 }, "value" : { "count" : 15 } }
{ "_id" : { "user" : "assaf", "day" : 1331856000000 }, "value" : { "count" : 57 } }
Somehow the date looks like an integer - I think this is some representation of the timestamp. If I do this:
PRIMARY> new Date(db.my_collection.find()[0]["_id"]["day"])
I will return the correct date:
ISODate("2012-03-19T00:00:00Z")
My question is how to do the same in pimongo. If I run any query in the above collection, pymongo returns documents in which the value dayis of type float with the same value as the timestamp:
dict: {u'_id': {u'user': u'ariel', u'day': 1332115200000.0}, u'value': {u'count': 99.0}}
How to enable this timestamp in Python datetime?
source
share