Mongoexport--help Export Parameter Help
Mongoimport--help Import Parameters Help
Summarize:
Mongoexport--host 172.20.41.xx--username--port xxx xxx--password 1234--db cmpdb--collection wangzs-f name-o E:\wan Gzs.dat
Mongoimport--host 172.20.41.xx--port xxx--username xxx--password 1234--db cmpdb--collection wangzstemp E:\wangzs.dat
The exported Wangzs.dat file is in JSON format, which includes the _id field, and the _id field is imported when the new import Wangzstemp collection, and the newly imported wangzstemp does not generate a new _id field. Common command grid mongodump-h IP--port Port-u username-p password-d database-o file existence path
If there are no users who can remove-u and-P
If you export the database for this computer, you can remove the-h
If the default port, you can remove the--port
If you want to export all databases, you can remove the-D
Run directly on Windows 1. Download MongoDB decompression D:\mongo\bin
2. Run command cmd, you can execute MONGO instruction
One: Export command
Mongoexport--host 172.20.41.25--port 88888--db ceairdb--collection mappuser-f nino,ppno,phone,namecn,nameen--csv-o D:\mappuser.csv
Mongoexport--host 172.20.41.50--port 27000--xxx--password xxx--db cmpdb--collection wangzs-f name,address--type=csv -O E:\wangzs.csv
3.2 3.4 version needs to use the--type=csv parameter description:
--host: Database Address
--port: Database port number
--DB: Database name
--collection:collection Name
-F: Export refers to fields, separated by commas
--csv: Indicates that the exported file format is CSV
-O: Export filename
Export all fields based on query criteria
Mongoexport--host 192.168.0.1--port 27117--db ceairdb--collection tsdata-q "{' lastevent ': ' Emdissue '}"-O D:\EMDDATA.C Sv
Mongoexport-h IP--port Port-u username-p password-D database-C table name-F field-Q condition export--csv-o file name
The above parameter is good to understand, the key point says:
-F: Export refers to fields, split by font size,-f name,email,age export name,email,age three fields
-Q: Can be exported by root query condition,-Q ' {' uid ': ' 100 '} ' to export UID 100 data
assertion:16619 code FailedToParse:FailedToParse:Expecting ' {': offset:0 If this error occurs, note the format of the following condition-Q
--csv indicates that the exported file format is CSV, which is useful because most relational databases are supported by CSV, where there is common
Two: Import command 1. Save Sanzima.xlsx as Sanzima.csv
2. Execute imongoimport command
Mongoimport--host 172.20.41.25--port 99999--db ceairdb--collection airportnew--type csv--headerline-file D:\sanz Ima.csv
Parameter description:
--host: Database Address
--port: Database port number
--DB: Database name
--collection:collection Name
--type: File type, indicating a CSV file
--headerline: Indicates that the first row is a column name and does not need to be imported
-file:csv file path and name
Mongoimport-h IP--port Port-u username-p password-D database-C table name--upsertfields field--drop filename
--upsertfields: Importing Fields
Garbled processing: If Excel has Chinese, special symbols, will throw the following exception: Exception:invalid UTF8 character detected
At this point, you need to convert the CSV file encoding to Utf-8 before executing the mongoimport command
Method: Upload the Pitags.csv to the Linux system, and then convert the encoding using the ICONV command:
Iconv-f gbk-t UTF-8 sanzima.csv > Sanzima2.csv
Reference: http://www.jb51.net/article/52498.htm