Getting timestamp from mongodb id

前端 未结 8 1777
误落风尘
误落风尘 2020-12-02 08:38

How do I get the timestamp from the MongoDB id?

8条回答
  •  执念已碎
    2020-12-02 09:10

    As of Mongo 2.2, this has changed (see: http://docs.mongodb.org/manual/core/object-id/)

    You can do this all in one step inside of the mongo shell:

    document._id.getTimestamp();
    

    This will return a Date object.

提交回复
热议问题