1

I'm trying to mongodump one specific collection but I need only 90 days behind. I'd to accomplish something like this:

db.collection.countDocuments({dateStart:{"$lt" : Date.now() - 90*24*60*60 * 1000 }});

Using mongodump, I do know to dump one collection like this:

mongoexport --db database --collection mycollection --username root --authenticationDatabase admin --password 'mypassword' -o /tmp/auditing.json

But I'd to mix it up with that query above.

Does anyone know if that's possible?

Thanks in advanced!

1 Answer 1

1

mongodump and mongoexport provide the --query option, see

https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--query and https://www.mongodb.com/docs/database-tools/mongoexport/#std-option-mongoexport.--query

Have a look at documentation, they provide examples. I guess you have to re-format the date, e.g. (in Linux):

mongoexport --db database --query='{"dateStart": { "$lt": { "$date": "'$(date --date="90 days ago" "+%FT%T%:z")'" } } }' ...

Your Answer

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

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