drop whole database within a single command of restoring the dump of mongodb

寵の児 提交于 2019-12-01 23:05:03

I didn't see an answer and I had the same question today.

You can drop the database before with:

use <db>
db.dropDatabase()

Or you can only drop the collection with:

db.<collection>.drop()

The problem with your command could be that something misses, like the database which you authenticate against or the user or maybe another thing.

In my setup this works

mongorestore --username=<user> --db=<database> --authenticationDatabase=<database> --dir=<dumpdir> --drop

If your dump was zipped beforehand, you can add the --gzip flag in the end.

You can find all that in the documentation for dropping a database or in the documentation of dropping a whole database. But please be cautious with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!