Mongorestore到另一个数据库 [英] Mongorestore to a different database

查看:454
本文介绍了Mongorestore到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MongoDB中,是否可以转储数据库并将内容还原到其他数据库?例如这样的

In MongoDB, is it possible to dump a database and restore the content to a different database? For example like this:

mongodump --db db1 --out dumpdir
mongorestore --db db2 --dir dumpdir

但是它不起作用.这是错误消息:

But it doesn't work. Here's the error message:

构建要从dumpdir dir恢复的集合列表

building a list of collections to restore from dumpdir dir

不知道如何处理子目录"dumpdir/db1",正在跳过...

don't know what to do with subdirectory "dumpdir/db1", skipping...

完成

推荐答案

您实际上需要指向目录位于"上一个转储的输出目录内:

You need to actually point at the "database name" container directory "within" the output directory from the previous dump:

mongorestore -d db2 dumpdir/db1

通常< path>可以用作位置参数,而不是使用-dir,只有在位置不正确"(即在参数列表的中间")时才需要使用-dir.

And usually just <path> is fine as a positional argument rather than with -dir which would only be needed when "out of position" i.e "in the middle of the arguments list".

p.s.对于存档备份文件(使用mongorestore v3进行已测试 .4.10)

p.s. For archive backup file (tested with mongorestore v3.4.10)

mongorestore --gzip --archive=${BACKUP_FILE_GZ} --nsFrom "${DB_NAME}.*" --nsTo "${DB_NAME_RESTORE}.*"

这篇关于Mongorestore到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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