Reputation: 14373
In our database it uses NumberLong to store timestamp. The question is which javascript function I can use to operate on the timestamp in mongodb shell?
For example, find out the time in millis of the next day of time NumberLong(1330828762699) and the beginning of the current day.
Upvotes: 4
Views: 4727
Reputation: 5662
1) "new Date()" in the mongo shell gets promoted to ISODate() so you can use the methods on that;
> new Date(1330828762699)
ISODate("2012-03-04T02:39:22.699Z")
> new Date(1330828762699).getMilliseconds()
699
2) With regards to timestamps on documents, did you know that there's a built-in create date you can use?
> ObjectId("5020317b92c3d21cb851fa1a").getTimestamp()
ISODate("2012-08-06T21:04:59Z")
3) I would take a look at the 2.2 aggregate framework for manipulating your data. It has some useful date functions you may be able to employ to make useful time-based queries over your data;
http://docs.mongodb.org/manual/reference/aggregation/#date-operators
Upvotes: 2