In which order does a mongodump --query executes, is from last insert to first insert or the other way around, if it is other way around is there any option that I can pass to mongodump --query, so that mongodump queries start from first insert to last insert,

any ideas?

  • In general, MongoDB collections are not maintained in insertion order on disk and queries that do not specify sort criteria similarly have an undefined order of results. This makes the insertion order irrelevant except in special cases such as capped collections. What is your goal in terms of dumping in insertion order? Are you working with a capped collection (or more specifically, the replication oplog)? – Stennie Jan 13 '16 at 6:16
  • I am specifically working with oplog which is a capped collection, right? – Prashanth Kumar B Jan 13 '16 at 9:38
  • Yes, the oplog is a capped collection. However, the oplog is used by the replication internals for MongoDB so there are some notable differences from a non-system capped collection. In particular, there are no indexes on the oplog so the only possibly query plan is a collection scan (COLLSCAN in explain output) and your mongodump results in this case will always be returned in forward natural order (which will be insertion order for the oplog entries that are present). – Stennie Jan 13 '16 at 12:37
  • So can I can i do some modifications to the below query, so that the query does not get stuck on a large database(which is happening right now)? mongodump --host $MONGODB_HOST:$MONGODB_PORT --authenticationDatabase admin -u $MONGODB_USERNAME -p $MONGODB_PASSWORD -d local -c oplog.rs -o backup/oplogDump/$currentTime --query '{"ts":{$gt: Timestamp( 1452157469, 37)}}' – Prashanth Kumar B Jan 14 '16 at 6:47
  • Dumping the latest entries in the oplog with mongodump is going to require a collection scan (i.e. paging through the full oplog and potentially evicting useful data from memory). I would look into a different backup strategy -- ideally one of the documented backup methods. – Stennie Jan 15 '16 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.