I'm trying to dump oplog.rs from local database, based on timestamp.
Query directly from mongo shell works but not from mongodump

Query from mongo shell

RS1:PRIMARY> db.oplog.rs.find({"ts" : {$gt : Timestamp(1591199252, 0)}})
{ "ts" : Timestamp(1591199252, 1), "t" : NumberLong(2), "h" : NumberLong(0), "v" : 2, "op" : "n", "ns" : "", "wall" : ISODate("2020-06-03T15:47:32.975Z"), "o" : { "msg" : "periodic noop" } }

Mongodump ends either with an error or with 0 dumped documents (depending on single quotes for timestamp value) :

1. Output with error

$ mongodump $credentials -d local -c oplog.rs --query '{"ts": {"$gt": Timestamp(1591199252, 0)}}' --out ~/test/ 
2020-06-11T16:54:36.317+0200    Failed: error parsing query as Extended JSON: invalid JSON input. Position: 15. Character: T

2. Output with 0 dumped documents

$ mongodump $credentials -d local -c oplog.rs --query '{"ts": {"$gt": "Timestamp(1591199252, 0)"}}' --out ~/test/
2020-06-11T16:59:28.264+0200    writing local.oplog.rs to
2020-06-11T16:59:30.232+0200    done dumping local.oplog.rs (0 documents)

1 Answer 1


Mongodump don't understand Timestamp-function, so...

mongodump $credentials -d local -c oplog.rs --query '{"ts":{"$timestamp":{"t":1591199252,"i":0}}}' --out /test/
  • Indeed, I didn't found this part in the doc. Just for information, here is the full query with comparator : --query '{"ts":{"$gt":{"$timestamp":{"t":1591199252,"i":0}}}}'
    – Mat_
    Jun 12, 2020 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.