将整个数据库放入一个还原mongodb转储的命令中 [英] drop whole database within a single command of restoring the dump of mongodb

查看:96
本文介绍了将整个数据库放入一个还原mongodb转储的命令中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试还原mongodb的目录转储.

I am trying to restore the directory dump of mongodb.

我在做

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.

推荐答案

我没有找到答案,我今天有相同的问题.

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

如果预先压缩了转储,则可以在末尾添加--gzip标志.

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.

这篇关于将整个数据库放入一个还原mongodb转储的命令中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆