简体   繁体   English

带有mongoskin的时间戳如何?

[英]timestamp with mongoskin how to?

For those who want to query for timestamp here's how you do that: 对于那些想查询时间戳的人,您可以按照以下方法进行操作:

> db.foo.find()
{ "_id" : ObjectId("4e43a21d84782019413162ed"), "a" : { "t" : 1313055261000, "i" : 1 } }
> db.foo.find({'a': {'$gte': new Timestamp(new Date(2011, 8-1, 11), 0) } })
{ "_id" : ObjectId("4e43a21d84782019413162ed"), "a" : { "t" : 1313055261000, "i" : 1 } }
> db.foo.find({'a': {'$gte': new Timestamp(new Date(2011, 8-1, 12), 0) } })

i find that example in mongodb's page... but if i want to insert a timestamp in mongodb using mongoskin following the example??? 我在mongodb的页面中找到了该示例...但是,如果我想在该示例之后使用mongoskin在mongodb中插入时间戳?

i try this: 我试试这个:

db.collection('times').insert({time: new Timestamp(new Date('2012-08-06'),0)})

this is the error: 这是错误:

ReferenceError: Timestamp is not defined

Well that's because Timestamp is not defined. 那是因为未定义Timestamp It's neither part of JavaScript nor Node. 它既不是JavaScript的一部分,也不是Node的一部分。 You should define it before using. 您应该在使用前定义它。 This should work: 这应该工作:

var mongoskin = require('mongoskin');
var Timestamp = mongoskin.BSONPure.Timestamp;

Note that this Timestamp s are for internal db use only ; 请注意,此Timestamp仅用于内部db why do you need them, when there are Date.now() and new Date().getTime() ? 当有Date.now()new Date().getTime()时,为什么需要它们?

Anyway, here's a link with some more details — http://mongodb.github.com/node-mongodb-native/api-bson-generated/timestamp.html . 无论如何,这里有一些更多详细信息的链接— http://mongodb.github.com/node-mongodb-native/api-bson-generation/timestamp.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM