mongodb转储并通过管道传递到其他数据库名称 [英] mongodb dump and pipe to other db name

查看:112
本文介绍了mongodb转储并通过管道传递到其他数据库名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mongodb版本3.2.12.我有两个本地数据库,"base1"和"base2"

Mongodb version 3.2.12. I have two local databases, "base1" and "base2"

我想将所有数据(所有集合)从base1复制到base2,替换那里的所有内容(例如,将生产转储到开发环境时).

I want to copy all data (all collections) from base1 over to base2, replacing everything there (like when dumping production to a dev environment).

是否有任何管道命令(或其他简单方式)可以做到这一点?

Any pipe command (or other simple way) to do this?

我尝试过

mongodump --archive --db base1 | mongorestore --db base2 --archive

列出了很多将base1.collectionname写入要在stdout上存档的文件",但是没有任何内容写入base2.

lists a lot of "writing base1.collectionname to archive on stdout", but nothing gets written to base2.

我也尝试过

mongodump --db base1 --gzip --archive=/path/to/file.gz
mongorestore --db base2 --gzip --archive=/path/to/file.gz

转储有效,还原仅显示创建存档意图",完成"

Dump works, restore just says "creating intents for archive", "done"

推荐答案

我遇到了同样的问题,经过一番谷歌搜索之后,我发现了这篇文章 https://stackoverflow.com/a/43810346/3785901

I come across the same issue and after some googling and search I found this post https://stackoverflow.com/a/43810346/3785901

我尝试了以下命令:

mongodump --host HOST:PORT --db SOURCE_DB --username USERNAME --password PASSWORD --archive | mongorestore --host HOST:PORT --nsFrom 'SOURCE_DB.*' --nsTo 'TARGET_DB.*' --username USERNAME --password PASSWORD  --archive --drop

,它就像一种魅力. 它应该适合您的情况,祝您好运.

and it works like a charm. It should work in your case, good luck.

这篇关于mongodb转储并通过管道传递到其他数据库名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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