MongoDB. read, search oplog based timestamp

> db.oplog.rs.find({},{"ts":1}).sort({$natural: -1})
{ "ts" : Timestamp(1406185666, 1) }  
{ "ts" : Timestamp(1406180043, 1) }  
{ "ts" : Timestamp(1406180033, 1) }  
{ "ts" : Timestamp(1406172831, 1) }  
{ "ts" : Timestamp(1406171938, 1) }  
{ "ts" : Timestamp(1405915291, 1) }  
{ "ts" : Timestamp(1405915131, 1) }  
{ "ts" : Timestamp(1405915019, 1) }  
{ "ts" : Timestamp(1405914592, 1) }  
{ "ts" : Timestamp(1405914581, 1) }  
{ "ts" : Timestamp(1405587944, 1) }  
{ "ts" : Timestamp(1405587920, 1) }  
{ "ts" : Timestamp(1405587468, 1) }  
{ "ts" : Timestamp(1405587432, 1) }  
{ "ts" : Timestamp(1405587393, 1) }  
{ "ts" : Timestamp(1405587294, 1) }  
{ "ts" : Timestamp(1405587074, 1) }  
{ "ts" : Timestamp(1405586117, 1) }  
{ "ts" : Timestamp(1405586069, 1) }  
{ "ts" : Timestamp(1405586054, 1) }  

I have a timestamp example from oplog.rs in my database. I do not know how to read it.

My questions:

  • let's say that today is August 13, 2014 8:28. I want to select the entire oplog from the last hour.
  • I want to see the entire oplog from August 12, 2014, from 9:00 to 15:00.
+4
source share
1 answer

Timestamp, oplog, BSON MongoDB. es Timestamp(es, ord) time_t Unix. - , . Timestamp $gt, $lt ..:

> db.ts.find()
{ "_id" : ObjectId("53eb914ff9b63e0dd3ca1a20"), "ts" : Timestamp(1406185666, 1) }
{ "_id" : ObjectId("53eb915cf9b63e0dd3ca1a21"), "ts" : Timestamp(1405914581, 1) }
{ "_id" : ObjectId("53eb917cf9b63e0dd3ca1a22"), "ts" : Timestamp(1406185666, 2) }

> db.ts.find({ "ts" : { "$gte" : Timestamp(1406185630, 1) } })
{ "_id" : ObjectId("53eb914ff9b63e0dd3ca1a20"), "ts" : Timestamp(1406185666, 1) }
{ "_id" : ObjectId("53eb917cf9b63e0dd3ca1a22"), "ts" : Timestamp(1406185666, 2) }

> db.ts.find({ "ts" : { "$gt" : Timestamp(1406185666, 1) } })
{ "_id" : ObjectId("53eb917cf9b63e0dd3ca1a22"), "ts" : Timestamp(1406185666, 2) }

( mongo),

, 13 2014 8:28. oplog

> var SECS_PER_HOUR = 3600
> var now = Math.floor((new Date().getTime()) / 1000) // seconds since epoch right now
> db.oplog.rs.find({ "ts" : { "$lt" : Timestamp(now, 1), "$gt" : Timestamp(now - SECS_PER_HOUR, 1) } })

oplog 12 2014 , 9:00 15:00.

- .

> var since = Math.floor(ISODate("2014-08-12T09:00:00.000Z").getTime() / 1000)
> var until = Math.floor(ISODate("2014-08-12T15:00:00.000Z").getTime() / 1000)
> db.oplog.rs.find({ "ts" : { "$lt" : Timestamp(until, 1), "$gt" : Timestamp(since, 1) } })
+6

All Articles