Suppose there is a user table in the database with two records in it. We want to export it.
Common export Methods
[Root @ localhost bin] #./export-D my_mongodb-C user-o User. dat
Connected to: 127.0.0.1
Exported 2 records
[Root @ localhost bin] # Cat user. dat
{"_ Id": {"$ oid": "4f81a4a1779282ca68fd8a5a" }," uid ": 2," username ":" Jerry "," Age ": 100}
{"_ Id": {"$ oid": "4f844d1847d25a9ce5f120c4"}, "uid": 1, "username": "Tom", "Age": 25}
[Root @ localhost bin] #
Parameter description
-D indicates the database used. In this example, "my_mongodb"-C indicates the table to be exported, and in this example, "user"
-O indicates the file name to be exported. In this example, it is "user. dat"
We can see from the above that the export method uses the JSON style.
Export CSV files
[Root @ localhost bin] #./export-D my_mongodb-C user -- CSV-F uid, username, age-
User_csv.dat
Connected to: 127.0.0.1
Exported 2 records
[Root @ localhost bin] # Cat user_csv.dat
UID, username, age
2, "Jerry", 100
1, "Tom", 25
[Root @ localhost bin] #
Data Import
Import JSON data
[Root @ localhost bin] #./configure import-D my_mongodb-C user. dat
Connected to: 127.0.0.1
Imported 2 objects
[Root @ localhost bin] #
Import CSV data
[Root @ localhost bin] #./Export Import-D my_mongodb-C user -- type CSV -- headerline -- File
User_csv.dat
Connected to: 127.0.0.1
Imported 3 objects
[Root @ localhost bin] # parameter description
-Type indicates the format of the file to be imported.
-Headerline: do not import the first line because the first line is the column name.
-File: Specifies the path of the file to be imported.