MongoDB export and import (6)

MongoDB export and import (6)

1. mongodb export

1. Introduction to parameters of export data link mongodb server:

  • -h host host
  • --port port port
  • -u username username
  • -p passwd password

2. Introduction of mongoexport export file parameters:

  • -d library name
  • -c table name
  • -f field1,field2...column names
  • -q query condition
  • -o export filename
  • -- csv export csv format (easy to exchange data with traditional databases)

2. Example of exporting data

1. Export the data whose xh number is less than or equal to 100 in the xh and name columns of the sdo table of the shop database, and export it to the current path. The saved file name is test.sdo.json


./mongoexport  -d shop -c sdo -f xh,name -q '{xh:{$lte:100}}' -o ./test.sdo.json

2. Export csv format to facilitate importing in mysql data.


./mongoexport  -d shop -c sdo -f _id,xh,name -q '{xh:{$lte:100}}' --csv -o ./test.sdo.csv

Three, mongodb import

Import data parameters:

  • -d database to be imported
  • -c The table to be imported (if it does not exist, it will be created by itself)
  • --type csv/json (default)
  • --file backup file path

Fourth, import data examples

1. Import the data of the test.sdo.json file in the current path into the teach table of the shop database, the format is json


./mongoimport -d shop -c teach --type json --file ./test.sdo.json

2. Import the csv file into the reach table of the shop database, and convert the format to json format. --headerline means to ignore header fields for csv data. such as id, name


CSV data table header fields need to be ignored.


Five, mongodb exports binary bson structure data and index information

Export the required parameters:

  • -d library name
  • -c table name
  • -f field1,field2...column names

Six, export bson data structure example

1. Syntax: mongodum -d test [-c table name] The default is to export to the dump directory under mongo

2. Export the sdo table data of the shop database to the default path.

3. View the exported data, which is placed in the dump directory by default


4. View the dump directory. The exported table generates two files: bson structure data and json data


5. If you do not declare the table name, export all the tables 

Seven, import bson structure data

-d : The database name for importing or restoring data, you can name it at will.

./dump/shop: Backup database path


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326720318&siteId=291194637