Use of MongoDB Export and Import commands

Source: Internet
Author: User

Mongodb provides easy-to-use export and import commands.

1. Introduction and use of export commands.

MongoDB provides a simple export tool, which is located in {MongoDB_HOME}/bin/mongoexport.exe, for example (My mongodb is deployed in a windows operating system and is similar in linux ):

The following describes how to use the export Export command: Export export-c gis-d local-o likehua. data

Where-c Represents ry

-D indicates the database

-O output file name.

For more parameters, see:

Administrator @ F523540 d:/Mongodb/bin
$ Export -- help
Export MongoDB data to CSV, TSV or JSON files.

Options:
-- Help produce help message
-V [-- verbose] be more verbose (include multiple times
For more verbosity e.g.-vvvvv)
-- Version print the program's version and exit
-H [-- host] arg mongo host to connect to (<set
Name>/S1, S2 for sets)
-- Port Arg server port. can also use -- Host
Hostname: Port
-- IPv6 enable IPv6 support (disabled
Default)
-U [-- username] Arg Username
-P [-- Password] Arg Password
-- Authenticationdatabase Arg user source (defaults to dbname)
-- Authenticationmechanic Arg (= MONGODB-CR)
Authentication Mechanism
-- Dbpath Arg directly access mongod database files
In the given path, instead
Connecting to a mongod server-needs
To lock the data directory, so cannot
Be used if a primary D is currently
Accessing the same path
-- Directoryperdb each db is in a separate directly
(Relevant only if dbpath specified)
-- Journal enable journaling (relevant only if
Dbpath specified)
-D [-- dB] Arg database to use
-C [-- collection] Arg collection to use (some commands)
-F [-- fields] Arg comma separated list of Field Names
E.g.-f name, age
-- FieldFile arg file with fields names-1 per line
-Q [-- query] arg query filter, as a JSON string
-- Csv export to csv instead of json
-O [-- out] arg output file; if not specified, stdout
Is used
-- JsonArray output to a json array rather than one
Object per line
-K [-- slaveOk] arg (= 1) use secondaries for export if
Available, default true
-- ForceTableScan force a table scan (do not use
$ Snapshot)

 

II. Introduction and use of import commands.

Import command location,

Usage:

Dministrator @ F523540 d:/Mongodb/bin
Export Import-d local-c gis -- type json -- file likehua. data-f username, _ id

-- Type: the data type of the imported data

-- File Name of the imported data

-F: Imported Fields

More parameters of the import command are described as follows:

Administrator @ F523540 d:/Mongodb/bin
$ Export Import -- help
Import CSV, TSV or JSON data into MongoDB.

When importing JSON documents, each document must be a separate line of the inpu
T file.

Example:
Export Import -- host myhost -- db my_cms -- collection docs <mydocfile. json

Options:
-- Help produce help message
-V [-- verbose] Be more verbose (include multiple times
For more verbosity e.g.-vvvvv)
-- Version print the program's version and exit
-H [-- host] arg mongo host to connect to (<set
Name>/s1, s2 for sets)
-- Port arg server port. Can also use -- host
Hostname: port
-- IPv6 enable IPv6 support (disabled
Default)
-U [-- username] Arg Username
-P [-- Password] Arg Password
-- Authenticationdatabase Arg user source (defaults to dbname)
-- Authenticationmechanic arg (= MONGODB-CR)
Authentication mechanism
-- Dbpath arg directly access mongod database files
In the given path, instead
Connecting to a mongod server-needs
To lock the data directory, so cannot
Be used if a primary D is currently
Accessing the same path
-- Directoryperdb each db is in a separate directly
(Relevant only if dbpath specified)
-- Journal enable journaling (relevant only if
Dbpath specified)
-D [-- dB] Arg database to use
-C [-- collection] Arg collection to use (some commands)
-F [-- fields] Arg comma separated list of Field Names
E.g.-F name, age
-- Fieldfile Arg file with fields names-1 per line
-- Ignoreblanks if given, empty fields in CSV and TSV
Will be ignored
-- Type arg type of file to import. default: json
(Json, csv, tsv)
-- File arg file to import from; if not specified
Stdin is used
-- Drop collection first
-- Headerline first line in input file is a header
(CSV and TSV only)
-- Upsert insert or update objects that already
Exist
-- Upsertfields Arg comma-separated fields for the query
Part of the upsert. You shoshould make
Sure this is indexed
-- Stoponerror stop importing at first error rather
Than continuing
-- Jsonarray load a JSON array, not one item per
Line. currently limited to 16 Mb.

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.