Mongodb runs on timestamps in long

In our database, it uses NumberLong to store the timestamp. The question is, what kind of javascript function can I use to work with timestamp in mongodb shell?

For example, find the time in milliseconds of the day of the next day, NumberLong (1330828762699) and the beginning of the current day.

+4
source share
1 answer

1) "new Date ()" in the mongo shell gets the status of ISODate (), so you can use the following methods:

> new Date(1330828762699) ISODate("2012-03-04T02:39:22.699Z") > new Date(1330828762699).getMilliseconds() 699 

2) Regarding timestamps on documents, do you know that you can use the built-in creation date?

 > ObjectId("5020317b92c3d21cb851fa1a").getTimestamp() ISODate("2012-08-06T21:04:59Z") 

3) I would like to take a look at the overall 2.2 framework for managing your data. It has some useful date functions that you can use to create useful time queries for your data;

http://docs.mongodb.org/manual/reference/aggregation/#date-operators

+2
source

Source: https://habr.com/ru/post/1416515/


All Articles