mongodb 如何将 mongodump 用于 1 个集合
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16347134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use mongodump for 1 collection
提问by user2325703
How can I use mongodump
to move a single collection from one database to another?
如何mongodump
将单个集合从一个数据库移动到另一个数据库?
How should I use the command and its options?
我应该如何使用命令及其选项?
回答by alecxe
I think it's just:
我认为这只是:
mongodump --db=<old_db_name> --collection=<collection_name> --out=data/
mongorestore --db=<new_db_name> --collection=<collection_name> data/<db_name>/<collection_name>.bson
Btw, the other way to move the collection from one database to another is to use renameCollection
:
顺便说一句,将集合从一个数据库移动到另一个数据库的另一种方法是使用renameCollection
:
db.runCommand({renameCollection:"<old_db_name>.<collection_name>",to:"<new_db_name>.<collection_name>"})
Here's some related SO threads:
这是一些相关的SO线程:
- How to copy a collection from one database to another in MongoDB
- How to use the dumped data by mongodump?
Hope that helps.
希望有帮助。
回答by Vaseem007
Taking database (document) dump (backup)
取数据库(文档)转储(备份)
mongodump --host <hostname-of-mongoserver> --db <db-name> --username <dbuser-name> --password <password> --gzip --out </backup/location/>
Taking collection dump (backup)
采取收集转储(备份)
mongodump --host <hostname-of-mongoserver> --db <db-name> --collection <collection-name> --username <dbuser-name> --password <password> --gzip --out </backup/location/>
回答by Anish Agarwal
Very basic commands for dump mongodb.
转储 mongodb 的非常基本的命令。
Dump all collection
mongodump
Dump specific database only
mongodump --db=DB_NAME
Dump database with username & password
mongodump -u=USERNAME -p=PASSWORD --db=DB_NAME
Dump from another host
mongodump --host HOST_NAME/HOST_IP --port HOST_PORT --out {YOUR_DIRECTOTY_PATH} --db=DB_NAME
转储所有集合
mongodump
仅转储特定数据库
mongodump --db=DB_NAME
使用用户名和密码转储数据库
mongodump -u=USERNAME -p=PASSWORD --db=DB_NAME
从另一个主机转储
mongodump --host HOST_NAME/HOST_IP --port HOST_PORT --out {YOUR_DIRECTOTY_PATH} --db=DB_NAME
Only able to dump from another host when they allow it.
只有在允许的情况下才能从另一台主机转储。