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

一世执手 提交于 2019-12-02 05:00:49

问题


I am trying to restore the directory dump of mongodb.

i am doing

mongorestore --db mydb --drop path/to/mydb/dump

But both does not able to restore the state of my dump. Any new records are visible even after restoring the db.

But no error is shown on console.


回答1:


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.



来源:https://stackoverflow.com/questions/22424347/drop-whole-database-within-a-single-command-of-restoring-the-dump-of-mongodb

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