簡體   English   中英

帶有mongoskin的時間戳如何?

[英]timestamp with mongoskin how to?

對於那些想查詢時間戳的人,您可以按照以下方法進行操作:

> 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) } })

我在mongodb的頁面中找到了該示例...但是,如果我想在該示例之后使用mongoskin在mongodb中插入時間戳?

我試試這個:

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

這是錯誤:

ReferenceError: Timestamp is not defined

那是因為未定義Timestamp 它既不是JavaScript的一部分,也不是Node的一部分。 您應該在使用前定義它。 這應該工作:

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

請注意,此Timestamp僅用於內部db 當有Date.now()new Date().getTime()時,為什么需要它們?

無論如何,這里有一些更多詳細信息的鏈接— 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