MongoDB backup, restore, export, import, clone operations sample _mongodb

Source: Internet
Author: User
Tags mongodb mongodump mongorestore

Database backup –mongodump

Back up all local MongoDB databases:

Copy Code code as follows:

# mongodump-h 127.0.0.1--port 27017-o/root/db/alldb

To back up a remote specified database:
Copy Code code as follows:

# mongodump-h 192.168.1.233--port 27018-d yourdb-o/root/db/yourdb

More Mongodump Detailed

Database Restore-mongorestore

Restore all databases to MongoDB:

Copy Code code as follows:

# mongorestore-h 127.0.0.1--port 27018/root/db/alldb

To restore the specified database:
Copy Code code as follows:

# Mongorestore--port 27017-d Yourdb/root/db/yourdb

More Mongorestore Detailed
Export Collection Data-mongoexport

To export data from a specified collection in a database:

Copy Code code as follows:

# mongoexport-h 192.168.1.233--port 27018-d yourdb-c Yourcoll-o/root/yourcoll.json

Exports the data from the specified field in the collection, and the exported file format is CSV:
Copy Code code as follows:

# mongoexport-d yourdb-c test-f "Id,name,score"--csv-o/root/test.csv

Export data based on criteria:
Copy Code code as follows:

# mongoexport-d Yourdb-c yourcoll-q ' {score:{$gt: '} '-o/root/yourcoll-bk.json

More Mongoexport Detailed

Collection Data Import-mongoimport

To restore the exported collection data:

Copy Code code as follows:

# mongoimport-d Yourdb-c Yourcoll--file/root/yourcoll.json

Import collection data, insert or update existing data:
Copy Code code as follows:

# mongoimport-d test-c yourcoll--file/root/yourcoll.json--upsert

More Mongoimport Detailed

MongoDB Database Cloning

Command format:

Copy Code code as follows:

Db.copydatabase (Fromdb, Todb, fromhost, username, password)

Copy the specified database from the remote MongoDB to the Local:
Copy Code code as follows:

# MONGO
> db.copydatabase ("Yii2", "Lyii2", "192.168.0.69")

More Db.copydatabase Detailed
Cloning of collections

Command format:

Copy Code code as follows:

Db.runcommand ({clonecollection: "<namespace>", From: "

Clones the specified collection from the remote MongoDB to the local database:
Copy Code code as follows:

# MONGO
> Db.runcommand ({clonecollection: "Test.user", From: "192.168.0.69", query:{}})

More Clonecollection Detailed

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.