MongoDB Remote database connection and backup import Export data

Source: Internet
Author: User
Tags mongodump

Environmental win10;

Run the CMD CD into the directory MongoDB Bin directory:

To connect to a remote MongoDB:

Connection command: Mongo-u username-p pwd host:post/database (database name)

When the user has the appropriate permissions, you can view the Collection==> View Collection command: Show collections

Export command:mongodump-h IP--port Port-u user name-p password-d database-o file exists path

Detailed Explanation:

    The server address where the-H:MONGODB is located (must specify a port), if not specified, is the local 127.0.0.1:27017

-U: User name

-P: Password

-D: The database that needs to be backed up (export entire mongodb is removed)

-O: Where the backed up data resides

Mongodump Backup RESTORE Database

Format: mongorestore-h IP--port Port-u user name-p password-d database--drop file exists path

--drop is the first to delete all data, and then restore, do not need to delete can not add;

Mongoexport Export the table, or export some of the fields in the table:

Command format: mongoexport-h IP--port Port-u user name-p password-D database-C table name-F field-Q conditional export--csv-o file name specific path (suffix format can be. dat or. csv);

mongoimport Import the table, or some of the fields in the table :

1. restore a non-CSV file exported from an entire table

   Command format: mongoimport-h IP--port Port-u user name-p password-D database-C table name--upsert--drop file name specific path (--drop when you do not need to delete the source file can not add)

2. restore the export file for some fields

  Command format: mongoimport-h IP--port Port-u user name-p password-D database-C table name--upsertfields field--drop file name specific path (--drop when you do not need to delete the source file can not add)

3. restore the exported CSV file (if the data is exported without the--CSV option, the exported data will have a lot of double quotes, the import will fail)

  Command format: mongoimport-h IP--port Port-u user name-p password-D database-C table name--type type (CSV)--headerline--upsert--drop file name specific path

Note: If the database has data, to import the most recent data, you need to add the--upsert option, update the data, or you will get an error (Prompt for duplicate key fault collection)

MongoDB Remote database connection and backup import Export data

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.