How to use mongodump to move only 1 collection from one database to another?
如何使用mongodump只将一个集合从一个数据库移动到另一个数据库?
How should I use the command and its options?
如何使用该命令及其选项?
3 个解决方案
#1
78
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:
这里有一些相关的线程:
- How to copy a collection from one database to another in MongoDB
- 如何在MongoDB中将集合从一个数据库复制到另一个数据库
- How to use the dumped data by mongodump?
- 如何使用mongodump的转储数据?
Hope that helps.
希望有帮助。
#2
10
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/>
mongodump文档
#3
5
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
Only able to dump from another host when they allow it.
只能在他们允许的时候从另一个主机上转储。
#1
78
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:
这里有一些相关的线程:
- How to copy a collection from one database to another in MongoDB
- 如何在MongoDB中将集合从一个数据库复制到另一个数据库
- How to use the dumped data by mongodump?
- 如何使用mongodump的转储数据?
Hope that helps.
希望有帮助。
#2
10
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/>
mongodump文档
#3
5
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
Only able to dump from another host when they allow it.
只能在他们允许的时候从另一个主机上转储。