2012-04-28 34 views
4

不能由specifing ts.t找到条目(TS是时间戳类型)MongoDB中无法找到specifing ts.t条目(TS是时间戳类型)

挖OPLOG,我想弄清楚有多少操作有一秒钟。

通过指定时间戳字段找不到条目,​​可以使用其他字段。 $ 在蒙戈外壳:

> 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 

回答

7

我相信TS场实际上是一个Timestamp场,控制台只是试图简化它为你(这确实使非常误导)。你可以这样做查询,它应该工作:

db.oplog.rs.find({ ts: Timestamp(1335200998000, 540)}); 

您可以使用$ GTE和$ LTE作为正常:

db.oplog.rs.find({ ts: {$gte: Timestamp(1335100998000, 1)}}); 
db.oplog.rs.find({ ts: {$lte: Timestamp(1335900998000, 1)}}); 

第二个参数是操作的递增顺序给定的第二内。

+1

它的工作原理,非常感谢。 – 2012-05-02 01:40:14

1

你只是简单地使用“.test”,而你不应该。以下作品:

db.oplog.rs.find({'ts.t': 1335200998000 }); 
+0

问题是ts.t是一个时间戳,谢谢你的帮助。 – 2012-05-02 01:39:45