Partial data removal before using mongorestore

Hi all,

mongodump tool offers --query parameter which allows to filter data to be dumped.
When using mongorestore thereafter, in some cases some data could be still there (causing duplicate key error) and it’s a good practice to clean them up first, before restoring from the dump. But, mongorestore only offers to drop the whole database before restoring from the dump.
Given I used --query in mongodump, I would also need to clean up data using the same query, before running mongorestore.
Meaning, I can’t drop the whole database, I only want to delete data given the query (for a specific date).

What is the easiest/simplest/most straightforward way to do this clean up?

I used to use:
mongo myhost:myport/myDb --eval “db.myCollection.remove({date: ISODate("${ISODATE}")})”

but the mongo shell is deprecated now, so maybe I need to move to mongosh now?

Thank you for your ideas.

Ivan

both mongo and mongosh should work. mongo is deprecated, but it is still supported.

So just use the clients to remote those data manually before restore.