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???
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. It's neither part of JavaScript nor 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 ; why do you need them, when there are Date.now()
and new Date().getTime()
?
Anyway, here's a link with some more details — http://mongodb.github.com/node-mongodb-native/api-bson-generated/timestamp.html .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.