1. Copying a database
1.1 db.copydatabase (fromdb,todb,fromhost,username,password,mechanism)
The following four options are optional:
Fromhost: The host address of the source DB, if it can be omitted within the same Mongod instance, username: If authentication mode is enabled, the user name of the MongoDB instance on the source DB host is required;
Password: ditto, need corresponding user's password; mechanism:fromhost verify username and password mechanism, there are: MONGODB-CR, scram-sha-1 two kinds.1.2 Db.runcommand (){copydb:1, fromhost: Fromhost: optional, see 1.1; Slaveok: Optional, set to true to allow data to be copied from secondary, at which point Fromehost must be set; Username: optional, see 1.1; Nonce: A one-time shared key generated on a remote server; Key: hash value for password
2. Copy Collection 2.1 RunCommandDb.runcommand ({clonecollection: <namespace> fromhost: Db.runcommand ({clonecollection: "Testdb.testcol", Fromhost: "192.168.1.12:27017", query:{"age": {"GT": 2}});
2.2 db.clonecollectionDb.clonecollection (from, collection, query)
Reference: https://docs.mongodb.com/manual/reference/method/db.copyDatabase/#db. copydatabase
https://docs.mongodb.com/manual/reference/command/copydb/https://docs.mongodb.com/manual/reference/command/ clonecollection/
https://docs.mongodb.com/manual/reference/method/db.cloneCollection/#db. clonecollection
https://docs.mongodb.com/manual/reference/command/clone/