MongoDB Study Notes (5)-data import/export Export

Source: Internet
Author: User
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.

 

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.