Mongodb replicates remote and local databases db.copyData
I also want to directly copy each other between mysqldbcopy and oracle 12c pdb. Copying, migrating data and preparing to develop a test environment will be addictive. Today, I want to migrate and prepare multiple sets of mongodb databases for production and test use. I found that mongodb also has this feature, and it is built-in. I am delighted to record it:
Db.copyDatabase:
Parameter description:
Db.copyDatabase (fromdb, todb, fromhost, username, password, mechanism)
The name of the fromdb:string source database. Users must be able to authenticate this db.
Todb:string is copied to the name of the destination mongod. The name can be different from the original name.
Fromhost:string optional ip+port ignores this item if it is the same mongd replication
Username:string optional source host username
Password: password for string optional source host username
Mechanism: there are two kinds of MONGODB-CR or SCRAM-SHA-1, db.isMaster (). If the maxWireVersion value is greater than or equal to 3, then the default is SCRAM-SHA-1, otherwise the default is MONGODB-CR (2.6 version authentication)
Db.copyDatabase ("db_chunqiu", "db_chunqiu", "192.168.56.105", "db_user", "db_user123")
Copy a database in the same instance:
Repsetzhou:PRIMARY > db.copyDatabase ("data", "data_1")
{"ok": 1}
Copy the remote database (192.168.56.105 db_chunqiu):
Repsetzhou:PRIMARY > db.copyDatabase ("db_chunqiu", "db_clone", "192.168.56.105 db_chunqiu", "db_user", "db_user123")
{"done": true, "ok": 1}
Repsetzhou:PRIMARY > show dbs
Admin 0.000GB
Data 0.030GB
Data_1 0.029GB
Db_clone 0.000GB
Local 0.101GB
Replicate the remote database (192.168.56.105 db_chunqiu) without password authentication:
Repsetzhou:PRIMARY > db.copyDatabase ("db_chunqiu", "db_clone2", "192.168.56.105pur27017")
{"ok": 1}