How to take backup based on ISODate or ObjectID using mongodump v4.2.2?

These will work on Windows OS. The first is a filter by ObjectId and the next by the date types:

> mongodump --db=test --collection=test --query="{ \"_id\": { \"$gte\" : { \"$oid\": \"5e58e938707edd40784daf83\" } } }"

> mongodump --db=test --collection=test --query="{ \"dt\": { \"$gte\" : { \"$date\": \"2020-02-26T01:00:00.000Z\" } } }"


The --queryFile option:

You can use the --queryFile option instead of the --query, in which case you can put the query filter JSON in a file. For example:

> mongodump --db=test --collection=test --queryFile=qry.json

and the qry.json has the following:
{ "_id": { "$gte" : { "$oid": "5e5911fe9476bac92059a747" } } }

Note the query file option’s JSON is cleaner without the backslash escapes.

4 Likes