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