Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongodb replicates remote and local databases db.copyData

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report