"MongoDB" MONGO copy databases and collections

Source: Internet
Author: User
Tags mongodb
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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.