mongorestore dropping collections using -drop option
Solution 1
No, actually, according to the official documentation :
--drop Before restoring the collections from the dumped backup, drops the collections from the target database. --drop does not drop collections that are not in the backup.
Solution 2
When used --drop, mongorestore will drop the collections if they are existing in both DB as well as in backup collection. It will not drop the collections which are not there in the Backup collection.
so in your example, collB will be dropped and restored, while collA remains untouched.
Related videos on Youtube
John Jai
Updated on June 04, 2022Comments
-
John Jai about 2 years
Suppose if I have a database testdb with two collections collA and collB and try to restore only collB from a dump.
Will using --drop option with mongorestore drops both the existing collections (collA and collB) from testdb even though only collB is in the dump?
I am using MongoDB 2.6.5
-
John Jai over 9 yearsI just tried to do a small testing, and see that one of the collection is not dropped if it's not part of the restored dump
-
wdberkeley over 9 yearsIn the same database? Are you sure? If so, that's a bug. It's documented to drop every collection in the targeted database before restoring.
-
John Jai over 9 yearsYes, I am sure it did not drop all the collections before restoring using the --drop option
-
hlynbech almost 4 yearsThe documentation says " --drop does not drop collections that are not in the backup."