PCB MongoDB Database Collection collection export and import

Source: Internet
Author: User
Tags log log mongodb

Since the use of Microsoft visual graphical interface has been used, and MongoDB is a command-type operation, and the system with the CMD operation is not convenient,

Here is a replacement of a cmd, the size of more than 100 m.

Cmder Tool Download Https://github.com/cmderdev/cmder/releases

The next operation is all done with the Cmder tool to perform the instruction Operation demo

I. Collection collection export and Import tool Description:

The relationship of the collection collection corresponding to SQL in NoSQL is equivalent to the concept of table, that is, the export and import of tables.

Export Collection Data tool Mongoexport.exe

Export Collection Data tool Mongoimport.exe

Two. Preparation phase

1. Start:Cmder.exe (if not installed, use CMD as Can)

2. Enter:D: for MongoDB installation disk

3. Input:CD D:\Program Files\mongodb\server\4.0\bin into the MongoDB installation directory

Three. Collection Collection Export--json format

" E:\db\ppeflow.json "

Parameter description:

-D PCBDB Database name

-C Ppeflow Collection name (equivalent to table name in SQL)

-O "e:\db\ppeflow.json" Output path

--TYPEO JSON default JSON output, of course, add this parameter into

Four. Collection collection Export--csv format

" _id,techname,orderid " " E:\db\ppeflow.csv "

Parameter description:

-D PCBDB Database name

-C Ppeflow Collection name (equivalent to table name in SQL)

--type CSV output format ( Note that there are 2 in front of the type-)

-F "_id,techname,orderid" output field name (between field and field, delimited)

-O "e:\db\ppeflow.csv" Output path

Five. Collection Collection Import--json format

Mongoimport.exe-d pcbdb-c Ppeflow1--file"e:\db\ppeflow.json"

Parameter description:

-D PCBDB Database name

-C Ppeflow1 Collection name (automatically created when not present)

-O "e:\db\ppeflow.json" Import JSON path

--TYPEO JSON default JSON input format, of course, add this parameter into

Six. Collection Collection Import--csv format

"_id, Techname,orderid " --file"e:\db\ppeflow.csv"

Parameter description:

-D PCBDB Database name

-C Ppeflow2 Collection name (equivalent to table name in SQL)

--type CSV output format ( Note that there are 2 in front of the type-)

-F "_id,techname,orderid" input field name (between field and field, delimited)

--file "E:\db\ppeflow.csv" read the CSV path ( Note that there are 2 in front of file-)

-headerline               Remove the first line of the word marked field (This example does not add this parameter, cause error, no workaround found)

Seven. Key parameter description
H,-- host : The database address that represents the remote connection, the local MONGO database is connected by default;-- Port: The remote port 27017 that represents the remote connection of the database, the default connection;- u,--Username: Represents the account connected to the remote database, if you set up the database authentication, you need to specify the user account;- P,--Password: the password corresponding to the account connected to the database;- D,-- db: Represents the connected database;- C,-- Collection: Represents a collection in a connected database;- F,-- fields: Represents the field in the Import collection;-- Type: Represents the imported file type, including CSV and JSON,TSV files, the default JSON format;--file: Imported file name--headerline: When importing a CSV file, indicate that the first row is a column name and does not need to be imported;

eight. Ask for answers

1. What is the text encoding type of the exported JSON and CSV format?

The exported text encoding type is (encoding) UTF8.

2. Using Excel to open CSV is garbled, how to solve it?

Method 1: Open with Notepad, then click the Menu "encode", "to ANSI encoding", and then open with Excel.

Method 2: Add conversions Using Excel to reference the text, refer to https://jingyan.baidu.com/article/48a4205705c098a925250455.html

3. Import csv to MongoDB minus the first line of the field row?

by Official document: In the import CSV parameter, add -headerline can

" _id,techname,orderid " --file"e:\db\ppeflow.csv"

But actually in the author's measurement, there is no solution. The following error is reported,

4.MongoDB export CSV to specify field export, can output JSON file specify field export?

No, the exported JSON file is all the fields in the entire integration.

5.MongoDB export CSV or JSON format, how to choose?

Please choose from the following comparison.

Size comparison: CSV takes advantage of fewer bytes

JSON takes up a lot of bytes

Deep structure comparison: CSV view is ambiguous for nested structure tree nodes that are larger than 2 layers. Advantages

JSON deep structure defines the structure with the JSON tree structure viewer,

Low-level structure comparison: CSV If you have a clear definition for <=2 nested tree sections, a draw

JSON low-level structure defines the structure clearly with a JSON tree structure viewer, a draw

field comparison: CSV optional field output, advantages

JSON full field output

Deserialization column: CSV not supported

JSON Support Benefits

6.MongoDB Import CSV Do you specify field input?

No, import CSV can not specify a field import, for example, there are 3 fields in the CSV, import into MongoDB can not only import the specified 2 fields

The specified field name here is a field name that is specified in each field in the CSV file and imported into MongoDB.

If the CSV has 3 fields and the imported field name is only 2, then the 3rd field in the CSV is by the MongoDB default Fled3 field

(Preferably the number of fields in the CSV, the number of field names to be imported, and the amount of field names that match the number of fields, in the same order)

7.MongoDB exported JSON, and then import, do not go in?

Because the export JSON will be the primary key _id that is ojbectid, output together, if you import the database again, there will be a primary key conflict

  Best solution: Import to another collection, and then through the 2 integrated unique primary key comparison, then the burst---conflict is not replaced, or conflict replacement)   

The follow-up study of MongoDB, mainly based on the existing functions of SQL, in MongoDB should also have the function of the corresponding implementation,

Next updates: NoSQL and SQL additions and deletions of the statement differences, primary key index, master-slave library replication, backup restore, request data and performance monitoring, log log, large-size file Gridfs.

PCB MongoDB Database Collection collection export and import

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.