Search code examples
mongodbtimestampmongooseprecisionmilliseconds

Can I get greater granularity out of a MongoDB timestamp?


I'm getting a timestamp from my MongoDB database, but it's coming back with precision only in the seconds:

Thu Jun 06 2013 16:15:22 GMT-0400 (Eastern Daylight Time)

I need greater granularity. Is there a way to get a MongoDB timestamp with precision in the milliseconds?

I'm making the call on my node.js server via mongoose:

var timestamp = new ObjectID().getTimestamp();

How can I get something more precise?


Solution

  • ObjectIds are stored with the precision of seconds and you can't change it. So if you need something of millis granularity then you have to store your own timestamp value.