Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb replicates remote and local databases db.copyData

Shulou Source: shulou.com Published: 2022-06-01 16:25:48 10月01日 Update

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}

Tags: Data database name user host password that is user name preparation test surprise function parameter name multiple sets instance version environment purpose development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Shulou Tech Info Xiaomi macOS