Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongorestore dropping collections using -drop option

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

like image 382
John Jai Avatar asked Mar 03 '15 17:03

John Jai


2 Answers

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.

like image 170
Sn00p Avatar answered Oct 14 '22 05:10

Sn00p


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.

like image 40
Khavasi Avatar answered Oct 14 '22 03:10

Khavasi