I've seen using strings, integer timestamps and mongo datetime objects.
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- Date with SimpleDateFormat in Java
- How to convert from Timestamp to Mongo ObjectID
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- How to truncate seconds in TSQL?
- How to remove seconds from datetime?
- OLS with pandas: datetime index as predictor
- MYSQL: How can I find 'last monday's date&
The best way is to store native JavaScript Date objects, which map onto BSON native Date objects.
The native type supports a whole range of useful methods out of the box, which you can use in your map-reduce jobs, for example.
If you need to, you can easily convert
Date
objects to and from Unix timestamps1), using thegetTime()
method andDate(milliseconds)
constructor, respectively.1) Strictly speaking, the Unix timestamp is measured in seconds. The JavaScript Date object measures in milliseconds since the Unix epoch.
One datestamp is already in the _id object, representing insert time
So if the insert time is what you need, it's already there:
Login to mongodb shell
Create your database by inserting items
Lets make that database the one we are on now
Get the rows back:
Get each row in yyyy-MM-dd HH:mm:ss format:
If that last one-liner confuses you I have a walkthrough on how that works here: https://stackoverflow.com/a/27613766/445131
Protip, MongoDB is best DB because MongoDB is web-scale: https://www.youtube.com/watch?v=b2F-DItXtZs