mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 09:06:21 +01:00
1414 lines
36 KiB
Groff
1414 lines
36 KiB
Groff
.\" Man page generated from reStructuredText.
|
|
.
|
|
.TH "MONGOIMPORT" "1" "Aug 16, 2019" "4.2" "mongodb-manual"
|
|
.SH NAME
|
|
mongoimport \- MongoDB Import Utility
|
|
.
|
|
.nr rst2man-indent-level 0
|
|
.
|
|
.de1 rstReportMargin
|
|
\\$1 \\n[an-margin]
|
|
level \\n[rst2man-indent-level]
|
|
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
|
-
|
|
\\n[rst2man-indent0]
|
|
\\n[rst2man-indent1]
|
|
\\n[rst2man-indent2]
|
|
..
|
|
.de1 INDENT
|
|
.\" .rstReportMargin pre:
|
|
. RS \\$1
|
|
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
|
|
. nr rst2man-indent-level +1
|
|
.\" .rstReportMargin post:
|
|
..
|
|
.de UNINDENT
|
|
. RE
|
|
.\" indent \\n[an-margin]
|
|
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
|
.nr rst2man-indent-level -1
|
|
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
|
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
|
|
..
|
|
.SS On this page
|
|
.INDENT 0.0
|
|
.IP \(bu 2
|
|
\fI\%Synopsis\fP
|
|
.IP \(bu 2
|
|
\fI\%Behavior\fP
|
|
.IP \(bu 2
|
|
\fI\%Required Access\fP
|
|
.IP \(bu 2
|
|
\fI\%Options\fP
|
|
.IP \(bu 2
|
|
\fI\%Examples\fP
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.IP "macOS Sierra and Go 1.6 Incompatibility"
|
|
.sp
|
|
Users running on macOS Sierra require the 3.2.10 or newer version
|
|
of mongoimport\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SH SYNOPSIS
|
|
.sp
|
|
The \fI\%mongoimport\fP tool imports content from an
|
|
Extended JSON, CSV, or TSV export
|
|
created by \fBmongoexport\fP, or potentially, another third\-party export
|
|
tool.
|
|
.sp
|
|
See the mongoexport document for more information regarding
|
|
\fBmongoexport\fP, which provides the inverse "exporting"
|
|
capability.
|
|
.sp
|
|
Run \fI\%mongoimport\fP from the system command line, not the \fBmongo\fP shell.
|
|
.SH BEHAVIOR
|
|
.sp
|
|
\fBWARNING:\fP
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
Avoid using \fI\%mongoimport\fP and \fBmongoexport\fP for
|
|
full instance production backups. They do not reliably preserve all rich
|
|
BSON data types, because JSON can only represent a subset
|
|
of the types supported by BSON. Use \fBmongodump\fP
|
|
and \fBmongorestore\fP as described in /core/backups for this
|
|
kind of functionality.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS JSON Format
|
|
.sp
|
|
Starting in MongoDB 4.2, \fI\%mongoimport\fP expects import data
|
|
to be in Extended JSON v2.0 (either Relaxed or Canonical mode)
|
|
by default. To recognize data that is in Extended JSON v1.0 format, see
|
|
\fI\%\-\-legacy\fP\&.
|
|
.sp
|
|
In earlier versions, \fI\%mongoimport\fP expects data in
|
|
/reference/mongodb\-extended\-json\-v1 format.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.SS Tip
|
|
.sp
|
|
In general, the versions of \fBmongoexport\fP and
|
|
\fI\%mongoimport\fP should match. That is, to import data
|
|
created from \fBmongoexport\fP, you should use the
|
|
corresponding version of \fI\%mongoimport\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS Encoding
|
|
.sp
|
|
\fI\%mongoimport\fP only supports data files that are UTF\-8 encoded.
|
|
Using other encodings will produce errors.
|
|
.SS FIPS
|
|
.sp
|
|
Starting in version 4.2, MongoDB removes the \fB\-\-sslFIPSMode\fP
|
|
option for mongoimport\&. mongoimport
|
|
will use FIPS compliant connections to
|
|
\fBmongod\fP/\fBmongos\fP if the
|
|
\fBmongod\fP/\fBmongos\fP instances are
|
|
configured to use FIPS mode\&.
|
|
.SS Write Concern
|
|
.sp
|
|
Starting in version 4.2, if you specify write concern in both the
|
|
\fI\%\-\-writeConcern\fP option and the
|
|
\fI\%\-\-uri connection string\fP option, the
|
|
\fI\%\-\-writeConcern\fP value overrides
|
|
the write concern specified in the URI string.
|
|
.sp
|
|
In earlier versions, the two options are incompatible.
|
|
.SH REQUIRED ACCESS
|
|
.sp
|
|
In order to connect to a \fBmongod\fP that enforces authorization
|
|
with the \fB\-\-auth\fP option, you must use the
|
|
\fB\-\-username\fP and \fB\-\-password\fP options. The connecting user must
|
|
possess, at a minimum, the \fBreadWrite\fP role on the database
|
|
into which they are importing data.
|
|
.SH OPTIONS
|
|
.sp
|
|
Changed in version 3.0.0: \fI\%mongoimport\fP removed the \fB\-\-dbpath\fP as well as related
|
|
\fB\-\-directoryperdb\fP and \fB\-\-journal\fP options. To use
|
|
\fI\%mongoimport\fP, you must run \fI\%mongoimport\fP against a running
|
|
\fBmongod\fP or \fBmongos\fP instance as appropriate.
|
|
|
|
.INDENT 0.0
|
|
.TP
|
|
.B mongoimport
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-help
|
|
Returns information on the options and use of \fBmongoimport\fP\&.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-verbose, \-v
|
|
Increases the amount of internal reporting returned on standard output
|
|
or in log files. Increase the verbosity with the \fB\-v\fP form by
|
|
including the option multiple times, (e.g. \fB\-vvvvv\fP\&.)
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-quiet
|
|
Runs \fBmongoimport\fP in a quiet mode that attempts to limit the amount
|
|
of output.
|
|
.sp
|
|
This option suppresses:
|
|
.INDENT 7.0
|
|
.IP \(bu 2
|
|
output from database commands
|
|
.IP \(bu 2
|
|
replication activity
|
|
.IP \(bu 2
|
|
connection accepted events
|
|
.IP \(bu 2
|
|
connection closed events
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-version
|
|
Returns the \fBmongoimport\fP release number.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-uri <connectionString>
|
|
New in version 3.4.6.
|
|
|
|
.sp
|
|
Specify a resolvable URI
|
|
connection string (enclose in quotes) to connect to the MongoDB deployment.
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
\-\-uri "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
For information on the components of the connection string, see
|
|
the Connection String URI Format documentation.
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
For TLS/SSL options, use the command\-line options instead of the
|
|
URI options for TLS/SSL (Available starting in
|
|
4.2)\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
\fBIMPORTANT:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
The following command\-line options cannot be used in conjunction
|
|
with \fI\%\-\-uri\fP option:
|
|
.INDENT 0.0
|
|
.IP \(bu 2
|
|
\fI\%\-\-host\fP
|
|
.IP \(bu 2
|
|
\fI\%\-\-port\fP
|
|
.IP \(bu 2
|
|
\fI\%\-\-db\fP
|
|
.IP \(bu 2
|
|
\fI\%\-\-username\fP
|
|
.IP \(bu 2
|
|
\fI\%\-\-password\fP (if the
|
|
URI connection string also includes the password)
|
|
.IP \(bu 2
|
|
\fI\%\-\-authenticationDatabase\fP
|
|
.IP \(bu 2
|
|
\fI\%\-\-authenticationMechanism\fP
|
|
.UNINDENT
|
|
.sp
|
|
Instead, specify these options as part of your \fI\%\-\-uri\fP
|
|
connection string.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-host <hostname><:port>, \-h <hostname><:port>
|
|
\fIDefault\fP: localhost:27017
|
|
.sp
|
|
Specifies a resolvable hostname for the \fBmongod\fP to which to
|
|
connect. By default, the \fBmongoimport\fP attempts to connect to a MongoDB
|
|
instance running on the localhost on port number \fB27017\fP\&.
|
|
.sp
|
|
To connect to a replica set, specify the
|
|
\fBreplSetName\fP and a seed list of set members, as in
|
|
the following:
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
\-\-host <replSetName>/<hostname1><:port>,<hostname2><:port>,<...>
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
When specifying the replica set list format, \fBmongoimport\fP always connects to
|
|
the primary\&.
|
|
.sp
|
|
You can also connect to any single member of the replica set by specifying
|
|
the host and port of only that member:
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
\-\-host <hostname1><:port>
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
Changed in version 3.0.0: If you use IPv6 and use the \fB<address>:<port>\fP format, you must
|
|
enclose the portion of an address and port combination in
|
|
brackets (e.g. \fB[<address>]\fP).
|
|
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-host\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-port <port>
|
|
\fIDefault\fP: 27017
|
|
.sp
|
|
Specifies the TCP port on which the MongoDB instance listens for
|
|
client connections.
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-port\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-ipv6
|
|
\fIRemoved in version 3.0.\fP
|
|
.sp
|
|
Enables IPv6 support and allows \fBmongoimport\fP to connect to the
|
|
MongoDB instance using an IPv6 network. Prior to MongoDB 3.0, you
|
|
had to specify \fI\%\-\-ipv6\fP to use IPv6. In MongoDB 3.0 and later, IPv6
|
|
is always enabled.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-ssl
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Enables connection to a \fBmongod\fP or \fBmongos\fP that has
|
|
TLS/SSL support enabled.
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-sslCAFile <filename>
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Specifies the \fB\&.pem\fP file that contains the root certificate chain
|
|
from the Certificate Authority. Specify the file name of the
|
|
\fB\&.pem\fP file using relative or absolute paths.
|
|
.sp
|
|
Starting in version 3.4, if \fB\-\-tlsCAFile\fP/\fBnet.tls.CAFile\fP (or
|
|
their aliases \fB\-\-sslCAFile\fP/\fBnet.ssl.CAFile\fP) is not specified
|
|
and you are not using x.509 authentication, the system\-wide CA
|
|
certificate store will be used when connecting to an TLS/SSL\-enabled
|
|
server.
|
|
.sp
|
|
To use x.509 authentication, \fB\-\-tlsCAFile\fP or \fBnet.tls.CAFile\fP
|
|
must be specified unless using \fB\-\-tlsCertificateSelector\fP or
|
|
\fB\-\-net.tls.certificateSelector\fP\&. Or if using the \fBssl\fP aliases,
|
|
\fB\-\-sslCAFile\fP or \fBnet.ssl.CAFile\fP must be specified unless using
|
|
\fB\-\-sslCertificateSelector\fP or \fBnet.ssl.certificateSelector\fP\&.
|
|
.sp
|
|
\fBWARNING:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
\fBVersion 3.2 and earlier:\fP For TLS/SSL connections (\fB\-\-ssl\fP) to
|
|
\fBmongod\fP and \fBmongos\fP, if the \fBmongoimport\fP runs without the
|
|
\fI\%\-\-sslCAFile\fP, \fBmongoimport\fP will not attempt
|
|
to validate the server certificates. This creates a vulnerability
|
|
to expired \fBmongod\fP and \fBmongos\fP certificates as
|
|
well as to foreign processes posing as valid \fBmongod\fP or
|
|
\fBmongos\fP instances. Ensure that you \fIalways\fP specify the
|
|
CA file to validate the server certificates in cases where
|
|
intrusion is a possibility.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-sslPEMKeyFile <filename>
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Specifies the \fB\&.pem\fP file that contains both the TLS/SSL certificate
|
|
and key. Specify the file name of the \fB\&.pem\fP file using relative
|
|
or absolute paths.
|
|
.sp
|
|
This option is required when using the \fI\%\-\-ssl\fP option to connect
|
|
to a \fBmongod\fP or \fBmongos\fP that has
|
|
\fBCAFile\fP enabled \fIwithout\fP
|
|
\fBallowConnectionsWithoutCertificates\fP\&.
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-sslPEMKeyPassword <value>
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Specifies the password to de\-crypt the certificate\-key file (i.e.
|
|
\fI\%\-\-sslPEMKeyFile\fP). Use the \fI\%\-\-sslPEMKeyPassword\fP option only if the
|
|
certificate\-key file is encrypted. In all cases, the \fBmongoimport\fP will
|
|
redact the password from all logging and reporting output.
|
|
.sp
|
|
If the private key in the PEM file is encrypted and you do not specify
|
|
the \fI\%\-\-sslPEMKeyPassword\fP option, the \fBmongoimport\fP will prompt for a passphrase. See
|
|
ssl\-certificate\-password\&.
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-sslCRLFile <filename>
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Specifies the \fB\&.pem\fP file that contains the Certificate Revocation
|
|
List. Specify the file name of the \fB\&.pem\fP file using relative or
|
|
absolute paths.
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-sslAllowInvalidCertificates
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Bypasses the validation checks for server certificates and allows
|
|
the use of invalid certificates. When using the
|
|
\fBallowInvalidCertificates\fP setting, MongoDB logs as a
|
|
warning the use of the invalid certificate.
|
|
.sp
|
|
Starting in MongoDB 4.0, if you specify
|
|
\fB\-\-sslAllowInvalidCertificates\fP or
|
|
\fBnet.ssl.allowInvalidCertificates: true\fP (or in MongoDB 4.2, the
|
|
alias \fB\-\-tlsAllowInvalidateCertificates\fP or
|
|
\fBnet.tls.allowInvalidCertificates: true\fP) when using x.509
|
|
authentication, an invalid certificate is only sufficient to
|
|
establish a TLS/SSL connection but is \fIinsufficient\fP for
|
|
authentication.
|
|
.sp
|
|
# We created a separate blurb for tls in the ssl\-clients page.
|
|
.sp
|
|
\fBWARNING:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
Although available, avoid using the
|
|
\fB\-\-sslAllowInvalidCertificates\fP option if possible. If the use of
|
|
\fB\-\-sslAllowInvalidCertificates\fP is necessary, only use the option
|
|
on systems where intrusion is not possible.
|
|
.sp
|
|
If the \fBmongo\fP shell (and other
|
|
mongodb\-tools\-support\-ssl) runs with the
|
|
\fB\-\-sslAllowInvalidCertificates\fP option, the
|
|
\fBmongo\fP shell (and other
|
|
mongodb\-tools\-support\-ssl) will not attempt to validate
|
|
the server certificates. This creates a vulnerability to expired
|
|
\fBmongod\fP and \fBmongos\fP certificates as
|
|
well as to foreign processes posing as valid
|
|
\fBmongod\fP or \fBmongos\fP instances. If you
|
|
only need to disable the validation of the hostname in the
|
|
TLS/SSL certificates, see \fB\-\-sslAllowInvalidHostnames\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-sslAllowInvalidHostnames
|
|
New in version 3.0.
|
|
|
|
.sp
|
|
Disables the validation of the hostnames in TLS/SSL certificates. Allows
|
|
\fBmongoimport\fP to connect to MongoDB instances even if the hostname in their
|
|
certificates do not match the specified hostname.
|
|
.sp
|
|
For more information about TLS/SSL and MongoDB, see
|
|
/tutorial/configure\-ssl and
|
|
/tutorial/configure\-ssl\-clients .
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-username <username>, \-u <username>
|
|
Specifies a username with which to authenticate to a MongoDB database
|
|
that uses authentication. Use in conjunction with the \fI\%\-\-password\fP and
|
|
\fI\%\-\-authenticationDatabase\fP options.
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-username\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-password <password>, \-p <password>
|
|
Specifies a password with which to authenticate to a MongoDB database
|
|
that uses authentication. Use in conjunction with the \fI\%\-\-username\fP and
|
|
\fI\%\-\-authenticationDatabase\fP options.
|
|
.sp
|
|
Changed in version 3.0.2: To prompt the user
|
|
for the password, pass the \fI\%\-\-username\fP option without
|
|
\fI\%\-\-password\fP or specify an empty string as the \fI\%\-\-password\fP value,
|
|
as in \fB\-\-password ""\fP .
|
|
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-password\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-authenticationDatabase <dbname>
|
|
Specifies the authentication database where the specified \fI\%\-\-username\fP has been created.
|
|
See user\-authentication\-database\&.
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-authenticationDatabase\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-authenticationMechanism <name>
|
|
\fIDefault\fP: SCRAM\-SHA\-1
|
|
.sp
|
|
Specifies the authentication mechanism the \fBmongoimport\fP instance uses to
|
|
authenticate to the \fBmongod\fP or \fBmongos\fP\&.
|
|
.sp
|
|
Changed in version 4.0: MongoDB removes support for the deprecated MongoDB
|
|
Challenge\-Response (\fBMONGODB\-CR\fP) authentication mechanism.
|
|
.sp
|
|
MongoDB adds support for SCRAM mechanism using the SHA\-256 hash
|
|
function (\fBSCRAM\-SHA\-256\fP).
|
|
|
|
.TS
|
|
center;
|
|
|l|l|.
|
|
_
|
|
T{
|
|
Value
|
|
T} T{
|
|
Description
|
|
T}
|
|
_
|
|
T{
|
|
SCRAM\-SHA\-1
|
|
T} T{
|
|
\fI\%RFC 5802\fP standard
|
|
Salted Challenge Response Authentication Mechanism using the SHA\-1
|
|
hash function.
|
|
T}
|
|
_
|
|
T{
|
|
SCRAM\-SHA\-256
|
|
T} T{
|
|
\fI\%RFC 7677\fP standard
|
|
Salted Challenge Response Authentication Mechanism using the SHA\-256
|
|
hash function.
|
|
.sp
|
|
Requires featureCompatibilityVersion set to \fB4.0\fP\&.
|
|
.sp
|
|
New in version 4.0.
|
|
T}
|
|
_
|
|
T{
|
|
MONGODB\-X509
|
|
T} T{
|
|
MongoDB TLS/SSL certificate authentication.
|
|
T}
|
|
_
|
|
T{
|
|
GSSAPI (Kerberos)
|
|
T} T{
|
|
External authentication using Kerberos. This mechanism is
|
|
available only in \fI\%MongoDB Enterprise\fP\&.
|
|
T}
|
|
_
|
|
T{
|
|
PLAIN (LDAP SASL)
|
|
T} T{
|
|
External authentication using LDAP. You can also use \fBPLAIN\fP
|
|
for authenticating in\-database users. \fBPLAIN\fP transmits
|
|
passwords in plain text. This mechanism is available only in
|
|
\fI\%MongoDB Enterprise\fP\&.
|
|
T}
|
|
_
|
|
.TE
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-authenticationMechanism\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-gssapiServiceName
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Specify the name of the service using GSSAPI/Kerberos\&. Only required if the service does not use the
|
|
default name of \fBmongodb\fP\&.
|
|
.sp
|
|
This option is available only in MongoDB Enterprise.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-gssapiHostName
|
|
New in version 2.6.
|
|
|
|
.sp
|
|
Specify the hostname of a service using GSSAPI/Kerberos\&. \fIOnly\fP required if the hostname of a machine does
|
|
not match the hostname resolved by DNS.
|
|
.sp
|
|
This option is available only in MongoDB Enterprise.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-db <database>, \-d <database>
|
|
Specifies the name of the database on which to run the \fBmongoimport\fP\&.
|
|
.sp
|
|
\fBNOTE:\fP
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
You cannot specify both \fI\%\-\-db\fP and \fI\%\-\-uri\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-collection <collection>, \-c <collection>
|
|
Specifies the collection to import.
|
|
.sp
|
|
New in version 2.6: If you do not specify \fI\%\-\-collection\fP,
|
|
\fI\%mongoimport\fP takes the collection name from the input
|
|
filename. MongoDB omits the extension of the file from the
|
|
collection name, if the input file has an extension.
|
|
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-fields <field1[,field2]>, \-f <field1[,field2]>
|
|
Specify a comma separated list of field names when importing csv
|
|
or tsv files that do not have field names in the first (i.e.
|
|
header) line of the file.
|
|
.sp
|
|
If you attempt to include \fI\%\-\-fields\fP when importing JSON data,
|
|
\fBmongoimport\fP will return an error. \fI\%\-\-fields\fP is only for csv
|
|
or tsv imports.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-fieldFile <filename>
|
|
As an alternative to \fI\%\-\-fields\fP, the \fI\%\-\-fieldFile\fP
|
|
option allows you to specify a file that holds a list of field names if
|
|
your csv or tsv file does not include field names in the
|
|
first line of the file (i.e. header). Place one field per line.
|
|
.sp
|
|
If you attempt to include \fI\%\-\-fieldFile\fP when importing JSON data,
|
|
\fBmongoimport\fP will return an error. \fI\%\-\-fieldFile\fP is only for csv
|
|
or tsv imports.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-ignoreBlanks
|
|
Ignores empty fields in csv and tsv exports. If not
|
|
specified, \fI\%mongoimport\fP creates fields without values in
|
|
imported documents.
|
|
.sp
|
|
If you attempt to include \fI\%\-\-ignoreBlanks\fP when importing JSON data,
|
|
\fBmongoimport\fP will return an error. \fI\%\-\-ignoreBlanks\fP is only for csv
|
|
or tsv imports.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-type <json|csv|tsv>
|
|
Specifies the file type to import. The default format is JSON,
|
|
but it\(aqs possible to import csv and tsv files.
|
|
.sp
|
|
The \fBcsv\fP parser accepts that data that complies with RFC
|
|
\fI\%RFC 4180\fP\&. As a result, backslashes are \fInot\fP a valid escape
|
|
character. If you use double\-quotes to enclose fields in the CSV
|
|
data, you must escape internal double\-quote marks by prepending
|
|
another double\-quote.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-file <filename>
|
|
Specifies the location and name of a file containing the data to import.
|
|
If you do not specify a file, \fI\%mongoimport\fP reads data from
|
|
standard input (e.g. "stdin").
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-drop
|
|
Modifies the import process so that the target instance drops
|
|
the collection before importing the data from the input.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-headerline
|
|
If using \fI\%\-\-type csv\fP or \fI\%\-\-type
|
|
tsv\fP, uses the first line as field names.
|
|
Otherwise, \fI\%mongoimport\fP will import the first line as a
|
|
distinct document.
|
|
.sp
|
|
If you attempt to include \fI\%\-\-headerline\fP when importing JSON data,
|
|
\fBmongoimport\fP will return an error. \fI\%\-\-headerline\fP is only for csv
|
|
or tsv imports.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-mode insert|upsert|merge
|
|
\fIDefault\fP: insert
|
|
.sp
|
|
New in version 3.4.
|
|
|
|
.sp
|
|
Specifies how the import process should handle existing documents
|
|
in the database that match documents in the import file.
|
|
.sp
|
|
By default, \fBmongoimport\fP uses the \fB_id\fP field to match documents in
|
|
the collection with documents in the import file.
|
|
To specify the fields against which to match existing
|
|
documents for the \fBupsert\fP and \fBmerge\fP modes,
|
|
use \fI\%\-\-upsertFields\fP\&.
|
|
.TS
|
|
center;
|
|
|l|l|.
|
|
_
|
|
T{
|
|
Value
|
|
T} T{
|
|
Description
|
|
T}
|
|
_
|
|
T{
|
|
\fBinsert\fP
|
|
T} T{
|
|
Insert the documents in the import file. \fBmongoimport\fP will log
|
|
an error if you attempt to import a document that contains a
|
|
duplicate value for a field with a unique index, such as \fB_id\fP\&.
|
|
T}
|
|
_
|
|
T{
|
|
\fBupsert\fP
|
|
T} T{
|
|
Replace existing documents in the database with matching
|
|
documents from the
|
|
import file. \fBmongoimport\fP will insert all other
|
|
documents. \fI\%Replace Matching Documents during Import\fP describes how to
|
|
use \fI\%\-\-mode\fP \fBupsert\fP\&.
|
|
T}
|
|
_
|
|
T{
|
|
\fBmerge\fP
|
|
T} T{
|
|
Merge existing documents that match a document in the import file with
|
|
the new document. \fBmongoimport\fP will insert all other documents.
|
|
\fI\%Merge Matching Documents during Import\fP describes how to use \fI\%\-\-mode\fP
|
|
\fBmerge\fP\&.
|
|
T}
|
|
_
|
|
.TE
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-upsertFields <field1[,field2]>
|
|
Specifies a list of fields for the query portion of the
|
|
upsert\&.
|
|
Use this option if the \fB_id\fP fields in the
|
|
existing documents don\(aqt match the field in the document, but
|
|
another field or field combination can uniquely identify
|
|
documents as a basis for performing upsert operations.
|
|
.sp
|
|
Changed in version 3.4: Modifies the import process to update existing objects in the
|
|
database if they match based on the specified fields, while
|
|
inserting all other objects. You do not need to use \fI\%\-\-mode
|
|
upsert\fP with \fI\%\-\-upsertFields\fP\&.
|
|
.sp
|
|
If you do not specify a field, \fI\%\-\-upsertFields\fP will upsert on the basis of
|
|
the \fB_id\fP field.
|
|
|
|
.sp
|
|
To ensure adequate performance, indexes should exist for this
|
|
field or fields.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-stopOnError
|
|
Forces \fBmongoimport\fP to halt the insert operation at the
|
|
first error rather than continuing the operation despite errors.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-jsonArray
|
|
Accepts the import of data expressed with multiple MongoDB documents
|
|
within a single JSON array. Limited to
|
|
imports of 16 MB or smaller.
|
|
.sp
|
|
Use \fI\%\-\-jsonArray\fP in conjunction with \fBmongoexport \-\-jsonArray\fP\&.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-legacy
|
|
Indicates that the import data is in Extended JSON v1 format instead of the default
|
|
Extended JSON v2 format\&.
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.SH TIP
|
|
.sp
|
|
In general, the versions of \fBmongoexport\fP and
|
|
\fI\%mongoimport\fP should match. That is, to import
|
|
data created from \fBmongoexport\fP, you should use
|
|
the corresponding version of \fI\%mongoimport\fP\&.
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
For example, if the import data is in v1 format:
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{"_id":1.0,"myregfield":{"$regex":"foo","$options":"i"}}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
Import without the \fI\%\-\-legacy\fP option results in
|
|
the following document in the collection:
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{ "_id" : 1, "myregfield" : { "$regex" : "foo", "$options" : "i" } }
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
Import with the \fI\%\-\-legacy\fP results in
|
|
the following document in the collection:
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{ "_id" : 1, "myregfield" : { "$regularExpression" : { "pattern" : "foo", "options" : "i" } } }
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
New in version 4.2.
|
|
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-maintainInsertionOrder
|
|
\fIDefault\fP: False
|
|
.sp
|
|
If specified, \fBmongoimport\fP inserts the documents in the order of
|
|
their appearance in the input source, otherwise \fBmongoimport\fP may
|
|
perform the insertions in an arbitrary order.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-numInsertionWorkers int
|
|
\fIDefault\fP: 1
|
|
.sp
|
|
New in version 3.0.0.
|
|
|
|
.sp
|
|
Specifies the number of insertion workers to run concurrently.
|
|
.sp
|
|
For large imports, increasing the number of insertion workers
|
|
may increase the speed of the import.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-writeConcern <document>
|
|
\fIDefault\fP: majority
|
|
.sp
|
|
Specifies the write concern for each write operation that \fBmongoimport\fP
|
|
performs.
|
|
.sp
|
|
Specify the write concern as a document with w options:
|
|
.INDENT 7.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
\-\-writeConcern "{w:\(aqmajority\(aq}"
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
If the write concern is also included in the \fI\%\-\-uri
|
|
connection string\fP, the command\-line
|
|
\fI\%\-\-writeConcern\fP overrides the write concern specified in
|
|
the URI string.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-bypassDocumentValidation
|
|
Enables \fBmongoimport\fP to bypass document validation
|
|
during the operation. This lets you insert documents that do not
|
|
meet the validation requirements.
|
|
.sp
|
|
New in version 3.2.1.
|
|
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-columnsHaveTypes
|
|
New in version 3.4.
|
|
|
|
.sp
|
|
Instructs \fBmongoimport\fP that the
|
|
field list specified in \fI\%\-\-fields\fP, \fI\%\-\-fieldFile\fP,
|
|
or \fI\%\-\-headerline\fP specifies the types of each field.
|
|
.sp
|
|
Field names must be in the form of \fB<colName>.<type>(<arg>)\fP\&. You
|
|
must backslash\-escape the following characters if you wish to include
|
|
them in an argument: \fB(\fP, \fB)\fP, and \fB\e\fP\&.
|
|
.TS
|
|
center;
|
|
|l|l|l|.
|
|
_
|
|
T{
|
|
\fBtype\fP
|
|
T} T{
|
|
Supported Arguments
|
|
T} T{
|
|
Example Header Field
|
|
T}
|
|
_
|
|
T{
|
|
\fBauto()\fP
|
|
T} T{
|
|
None.
|
|
T} T{
|
|
\fBmisc.auto()\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBbinary(<arg>)\fP
|
|
T} T{
|
|
.INDENT 7.0
|
|
.IP \(bu 2
|
|
\fBbase32\fP (\fI\%RFC4648\fP encoding schema)
|
|
.IP \(bu 2
|
|
\fBbase64\fP (\fI\%RFC4648\fP encoding schema)
|
|
.IP \(bu 2
|
|
\fBhex\fP
|
|
.UNINDENT
|
|
T} T{
|
|
\fBuser thumbnail.binary(base64)\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBboolean()\fP
|
|
T} T{
|
|
None.
|
|
T} T{
|
|
\fBverified.boolean()\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBdate(<arg>)\fP
|
|
T} T{
|
|
Alias for \fBdate_go(<arg>)\fP\&. \fI\%Go Language time.Parse format\fP\&.
|
|
T} T{
|
|
\fBcreated.date(2006\-01\-02 15:04:05)\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBdate_go(<arg>)\fP
|
|
T} T{
|
|
\fI\%Go Language time.Parse format\fP
|
|
T} T{
|
|
\fBcreated.date_go(2006\-01\-02 15:04:05)\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBdate_ms(<arg>)\fP
|
|
T} T{
|
|
\fI\%Microsoft SQL Server FORMAT format\fP
|
|
T} T{
|
|
\fBcreated.date_ms(yyyy\-MM\-dd H:mm:ss)\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBdate_oracle(<arg>)\fP
|
|
T} T{
|
|
\fI\%Oracle Database TO_DATE format\fP\&.
|
|
T} T{
|
|
\fBcreated.date_oracle(YYYY\-MM\-DD HH24:MI:SS)\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBdecimal()\fP
|
|
T} T{
|
|
None
|
|
T} T{
|
|
\fBprice.decimal()\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBdouble()\fP
|
|
T} T{
|
|
None.
|
|
T} T{
|
|
\fBrevenue.double()\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBint32()\fP
|
|
T} T{
|
|
None.
|
|
T} T{
|
|
\fBfollowerCount.int32()\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBint64()\fP
|
|
T} T{
|
|
None.
|
|
T} T{
|
|
\fBbigNumber.int64()\fP
|
|
T}
|
|
_
|
|
T{
|
|
\fBstring()\fP
|
|
T} T{
|
|
None.
|
|
T} T{
|
|
\fBzipcode.string()\fP
|
|
T}
|
|
_
|
|
.TE
|
|
.sp
|
|
See \fI\%Import CSV with Specified Field Types\fP for sample usage.
|
|
.sp
|
|
If you attempt to include \fI\%\-\-columnsHaveTypes\fP when importing JSON data,
|
|
\fBmongoimport\fP will return an error. \fI\%\-\-columnsHaveTypes\fP is only for csv
|
|
or tsv imports.
|
|
.UNINDENT
|
|
.INDENT 0.0
|
|
.TP
|
|
.B \-\-parseGrace <grace>
|
|
\fIDefault\fP: stop
|
|
.sp
|
|
New in version 3.4.
|
|
|
|
.sp
|
|
Specifies how \fBmongoimport\fP handles type coercion failures when importing
|
|
CSV or TSV files with \fI\%\-\-columnsHaveTypes\fP\&.
|
|
.sp
|
|
\fI\%\-\-parseGrace\fP has no effect when importing JSON documents.
|
|
.TS
|
|
center;
|
|
|l|l|.
|
|
_
|
|
T{
|
|
Value
|
|
T} T{
|
|
Description
|
|
T}
|
|
_
|
|
T{
|
|
\fBautoCast\fP
|
|
T} T{
|
|
Assigns a type based on the value of the field.
|
|
For example, if a field is defined as a \fBdouble\fP and the
|
|
value for that field was \fB"foo"\fP, \fBmongoimport\fP would make
|
|
that field value a string type.
|
|
T}
|
|
_
|
|
T{
|
|
\fBskipField\fP
|
|
T} T{
|
|
For the row being imported, \fBmongoimport\fP does not include the
|
|
field whose type does not match the expected type.
|
|
T}
|
|
_
|
|
T{
|
|
\fBskipRow\fP
|
|
T} T{
|
|
\fBmongoimport\fP does not import rows containing a value whose
|
|
type does not match the expected type.
|
|
T}
|
|
_
|
|
T{
|
|
\fBstop\fP
|
|
T} T{
|
|
\fBmongoimport\fP returns an error that ends the import.
|
|
T}
|
|
_
|
|
.TE
|
|
.UNINDENT
|
|
.SH EXAMPLES
|
|
.SS Simple Import
|
|
.sp
|
|
\fI\%mongoimport\fP restores a database from a backup taken with
|
|
\fBmongoexport\fP\&. Most of the arguments to \fBmongoexport\fP also
|
|
exist for \fI\%mongoimport\fP\&.
|
|
.sp
|
|
In the following example, \fI\%mongoimport\fP imports
|
|
the JSON data from the \fBcontacts.json\fP file into the collection
|
|
\fBcontacts\fP in the \fBusers\fP database.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-\-db users \-\-collection contacts \-\-file contacts.json
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS Replace Matching Documents during Import
|
|
.sp
|
|
Changed in version 3.4: In MongoDB 3.4, \fI\%\-\-mode upsert\fP replaces the
|
|
deprecated \fB\-\-upsert\fP option.
|
|
|
|
.sp
|
|
With \fI\%\-\-mode\fP \fBupsert\fP, \fI\%mongoimport\fP replaces
|
|
existing documents in the database that match a document in the
|
|
import file with the document from the import file.
|
|
Documents that do not match an existing document in the database are
|
|
inserted as usual. By default \fI\%mongoimport\fP matches documents
|
|
based on the \fB_id\fP field. Use \fI\%\-\-upsertFields\fP to specify
|
|
the fields to match against.
|
|
.sp
|
|
Consider the following document in the \fBpeople\fP collection in the
|
|
\fBexample\fP database:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{
|
|
"_id" : ObjectId("580100f4da893943d393e909"),
|
|
"name" : "Crystal Duncan",
|
|
"region" : "United States",
|
|
"email" : "crystal@example.com"
|
|
}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
The following document exists in a \fBpeople\-20160927.json\fP JSON file.
|
|
The \fB_id\fP field of the JSON object matches the \fB_id\fP field of the
|
|
document in the \fBpeople\fP collection.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{
|
|
"_id" : ObjectId("580100f4da893943d393e909"),
|
|
"username" : "crystal",
|
|
"likes" : [ "running", "pandas", "software development" ]
|
|
}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
To import the \fBpeople\-20160927.json\fP file and replace documents in
|
|
the database that match the documents in the import file, specify \fI\%\-\-mode\fP
|
|
\fBupsert\fP, as in the following:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-c people \-d example \-\-mode upsert \-\-file people\-20160927.json
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
The document in the \fBpeople\fP collection would then contain only
|
|
the fields from the imported document, as in the following:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{
|
|
"_id" : ObjectId("580100f4da893943d393e909"),
|
|
"username" : "crystal",
|
|
"likes" : [ "running", "pandas", "software development" ]
|
|
}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS Merge Matching Documents during Import
|
|
.sp
|
|
New in version 3.4.
|
|
|
|
.sp
|
|
With \fI\%\-\-mode\fP \fBmerge\fP, \fI\%mongoimport\fP enables you to
|
|
merge fields from a new record with an existing document in the
|
|
database. Documents that do not match an existing document in the
|
|
database are inserted as usual. By default \fI\%mongoimport\fP
|
|
matches documents based on the \fB_id\fP field. Use
|
|
\fI\%\-\-upsertFields\fP to specify the fields to match against.
|
|
.sp
|
|
The \fBpeople\fP collection in the \fBexample\fP database contains the
|
|
following document:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{
|
|
"_id" : ObjectId("580100f4da893943d393e909"),
|
|
"name" : "Crystal Duncan",
|
|
"region" : "United States",
|
|
"email" : "crystal@example.com"
|
|
}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
The following document exists in a \fBpeople\-20160927.json\fP JSON file.
|
|
The \fB_id\fP field of the JSON object matches the \fB_id\fP field of the
|
|
document in the \fBpeople\fP collection.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{
|
|
"_id" : ObjectId("580100f4da893943d393e909"),
|
|
"username" : "crystal",
|
|
"email": "crystal.duncan@example.com",
|
|
"likes" : [ "running", "pandas", "software development" ]
|
|
}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
To import the \fBpeople\-20160927.json\fP file and merge documents from
|
|
the import file with matching documents in the database, specify
|
|
\fI\%\-\-mode\fP \fBmerge\fP, as in the following:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-c people \-d example \-\-mode merge \-\-file people\-20160927.json
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
The import operation combines the fields from the JSON file with the
|
|
original document in the database,
|
|
matching the documents based on the \fB_id\fP field.
|
|
During the import process, \fI\%mongoimport\fP adds the new \fBusername\fP and
|
|
\fBlikes\fP fields to the document and updates the \fBemail\fP field with
|
|
the value from the imported document, as in the following:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
{
|
|
"_id" : ObjectId("580100f4da893943d393e909"),
|
|
"name" : "Crystal Duncan",
|
|
"region" : "United States",
|
|
"email" : "crystal.duncan@example.com",
|
|
"username" : "crystal",
|
|
"likes" : [
|
|
"running",
|
|
"pandas",
|
|
"software development"
|
|
]
|
|
}
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS Import \fBJSON\fP to Remote Host Running with Authentication
|
|
.sp
|
|
In the following example, \fI\%mongoimport\fP imports data from the
|
|
file \fB/opt/backups/mdb1\-examplenet.json\fP into the \fBcontacts\fP collection
|
|
within the database \fBmarketing\fP on a remote MongoDB
|
|
database with authentication enabled.
|
|
.sp
|
|
\fI\%mongoimport\fP connects to the \fBmongod\fP instance running on
|
|
the host \fBmongodb1.example.net\fP over port \fB37017\fP\&. It authenticates with the
|
|
username \fBuser\fP and the password \fBpass\fP\&.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-\-host mongodb1.example.net \-\-port 37017 \-\-username user \-\-password "pass" \-\-collection contacts \-\-db marketing \-\-file /opt/backups/mdb1\-examplenet.json
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS \fBCSV\fP Import
|
|
.SS General CSV Import
|
|
.sp
|
|
In the following example, \fI\%mongoimport\fP imports the csv
|
|
formatted data in the \fB/opt/backups/contacts.csv\fP file into the
|
|
collection \fBcontacts\fP in the \fBusers\fP database on the MongoDB
|
|
instance running on the localhost port numbered
|
|
\fB27017\fP\&.
|
|
.sp
|
|
Specifying \fI\%\-\-headerline\fP instructs
|
|
\fI\%mongoimport\fP to determine the name of the fields using the first
|
|
line in the CSV file.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-\-db users \-\-collection contacts \-\-type csv \-\-headerline \-\-file /opt/backups/contacts.csv
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
\fI\%mongoimport\fP uses the input file name, without the
|
|
extension, as the collection name if \fB\-c\fP or \fB\-\-collection\fP is
|
|
unspecified. The following example is therefore equivalent:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-\-db users \-\-type csv \-\-headerline \-\-file /opt/backups/contacts.csv
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS Import CSV with Specified Field Types
|
|
.sp
|
|
New in version 3.4.
|
|
|
|
.sp
|
|
MongoDB 3.4 added support for specifying field types. Specify field
|
|
names and types in the form \fB<colName>.<type>(<arg>)\fP using
|
|
\fI\%\-\-fields\fP, \fI\%\-\-fieldFile\fP, or \fI\%\-\-headerline\fP\&.
|
|
.sp
|
|
Consider the following CSV data:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
Katherine Gray, 1996\-02\-03, F, 1235, TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlzIG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBpbiByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xvcmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNhdCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lhIGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg==
|
|
Albert Gilbert, 1992\-04\-24, T, 13, Q3VwY2FrZSBpcHN1bSBkb2xvciBzaXQgYW1ldCB0b290c2llIHJvbGwgYm9uYm9uIHRvZmZlZS4gQ2FuZHkgY2FuZXMgcGllIGNyb2lzc2FudCBjaG9jb2xhdGUgYmFyIGxvbGxpcG9wIGJlYXIgY2xhdyBtYWNhcm9vbi4gU3dlZXQgcm9sbCBjdXBjYWtlIGNoZWVzZWNha2Ugc291ZmZsw6kgYnJvd25pZSBpY2UgY3JlYW0uIEp1anViZXMgY2FrZSBjdXBjYWtlIG1hY2Fyb29uIGRhbmlzaCBqZWxseS1vIHNvdWZmbMOpLiBDYWtlIGFwcGxlIHBpZSBnaW5nZXJicmVhZCBjaG9jb2xhdGUgc3VnYXIgcGx1bS4gU3dlZXQgY2hvY29sYXRlIGNha2UgY2hvY29sYXRlIGNha2UganVqdWJlcyB0aXJhbWlzdSBvYXQgY2FrZS4gU3dlZXQgc291ZmZsw6kgY2hvY29sYXRlLiBMaXF1b3JpY2UgY290dG9uIGNhbmR5IGNob2NvbGF0ZSBtYXJzaG1hbGxvdy4gSmVsbHkgY29va2llIGNha2UgamVsbHkgYm
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.sp
|
|
The \fI\%\-\-fields\fP option specifies which
|
|
field type \fI\%mongoimport\fP will use when importing the data
|
|
into MongoDB.
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-\-db users \-\-collection contacts \-\-type csv \-\-columnsHaveTypes \-\-fields "name.string(),birthdate.date(2006\-01\-02),contacted.boolean(),followerCount.int32(),user thumbnail.binary(base64)" \-\-file /example/file.csv
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SS Ignore Blank Fields
|
|
.sp
|
|
Use the \fI\%\-\-ignoreBlanks\fP option
|
|
to ignore blank fields. For CSV and TSV imports, this
|
|
option provides the desired functionality in most cases because it avoids
|
|
inserting fields with null values into your collection.
|
|
.sp
|
|
The following example imports the data from \fBdata.csv\fP, skipping
|
|
any blank fields:
|
|
.INDENT 0.0
|
|
.INDENT 3.5
|
|
.sp
|
|
.nf
|
|
.ft C
|
|
mongoimport \-\-db users \-\-collection contacts \-\-type csv \-\-file /example/data.csv \-\-ignoreBlanks
|
|
.ft P
|
|
.fi
|
|
.UNINDENT
|
|
.UNINDENT
|
|
.SH AUTHOR
|
|
MongoDB Documentation Project
|
|
.SH COPYRIGHT
|
|
2008-2019
|
|
.\" Generated by docutils manpage writer.
|
|
.
|