Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 983
Mike Pateras Avatar asked Jun 06 '13 20:06

Mike Pateras


1 Answers

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.

like image 182
Abhishek Kumar Avatar answered Sep 19 '22 13:09

Abhishek Kumar