Cannot find entry by specifing ts.t(ts is a Timestamp type)
Digging the oplog, I want to figure out how many operations there are in a second.
Cannot find entry by specifing a timestamp field, ok with other fields. $ In mongo shell:
> db.oplog.rs.findOne()
{
"ts" : {
"t" : 1335200998000,
"i" : 540
},
"h" : NumberLong("4405509386688070776"),
"op" : "i",
"ns" : "new_insert",
"o" : {
"_id" : ObjectId("4f958fad55ba26db6a000a8b"),
"username" : "go9090",
"message" : "hello, test.",
}
}
> db.oplog.rs.find().count()
419583
> db.oplog.rs.test.find({"ts.t":1335200998000}).count()
0
> db.oplog.rs.test.find({"ts.t":/^1335200998/}).count()
0
> db.oplog.rs.test.find({ts:{ "t" : 1335200998000, "i" : 540 }}).count()
0
I believe the ts field is actually a Timestamp field, the console just tries to simplify it for you (which does make it very misleading). You can do the query like this and it should work:
db.oplog.rs.find({ ts: Timestamp(1335200998000, 540)});
You can use $gte and $lte as normal:
db.oplog.rs.find({ ts: {$gte: Timestamp(1335100998000, 1)}});
db.oplog.rs.find({ ts: {$lte: Timestamp(1335900998000, 1)}});
The second argument is an incremental ordinal for operations within a given second.
You're simply using ".test" while you shouldn't be. The following works:
db.oplog.rs.find( {'ts.t': 1335200998000 } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With