【发布时间】:2011-11-11 17:46:57
【问题描述】:
我正在使用 Mongo shell 来查询我的 Mongo 数据库。我想使用 ObjectID 中包含的时间戳作为我的查询的一部分,也作为一列提取到输出中。我已经设置 Mongo 自己创建 ObjectID。
我的问题是我不知道如何使用 ObjectID 来提取其时间戳。
以下是我正在尝试解决的问题。 “createdDate”字段是占位符;不确定正确的字段是什么:
//Find everything created since 1/1/2011
db.myCollection.find({date: {$gt: new Date(2011,1,1)}});
//Find everything and return their createdDates
db.myCollection.find({},{createdDate:1});
【问题讨论】:
标签: shell mongodb timestamp unix-timestamp