mapreduce - Emit a DateTime in the Map function of MongoDb -


my map function looks this:

map = function() {    day = date.utc(this.timestamp.getfullyear(), this.timestamp.getmonth(), this.timestamp.getdate());    emit({day : day, store_id : this.store_id}, {count : 1}); } 

timestamp stored date in database, this:

{ "timestamp" : "mon mar 01 2010 11:58:09 gmt+0000 (bst)", ...} 

i need "day" in result collection stored date type well, it's stored long (epoch ticks) this:

{ "_id" : { "day" : 1265414400000, "store_id" : 10}, "value" : { "count" : 7 } } 

i tried changing emit didn't help:

emit({day : {"$date" : day},...) 

any ideas how that?

date.utc going return miliseconds epoch. when put data db, can use example:

 new date(dateaslong) 

and stored bson date format.

earlier mongo 1.7 show in hash as:

 "mon mar 01 2010 11:58:09 gmt+0000 (bst)" 

1.7+ appear as:

 isodate("2010-03-01t11:58:09z") 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -