.\" Man page generated from reStructuredText. . .TH "MONGOIMPORT" "1" "Oct 24, 2019" "4.0" "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\%Considerations\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 CONSIDERATIONS .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 .sp \fBmongoexport\fP and \fI\%mongoimport\fP use the strict mode representation for certain types. .sp \fI\%mongoimport\fP only supports data files that are UTF\-8 encoded. Using other encodings will produce errors. .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 New in version 3.4.6. .sp Specify a resolvable URI connection string 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 more information on the components of the connection string, see the Connection String URI Format documentation. .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 <:port>, \-h <: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 /<:port>,<: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 <:port> .ft P .fi .UNINDENT .UNINDENT .sp Changed in version 3.0.0: If you use IPv6 and use the \fB
:\fP format, you must enclose the portion of an address and port combination in brackets (e.g. \fB[
]\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 \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 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\-\-sslCAFile\fP or \fBssl.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 If using x.509 authentication, \fB\-\-sslCAFile\fP or \fBssl.CAFile\fP must be specified unless using \fB\-\-sslCertificateSelector\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 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 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 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 \fBssl.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 \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 \-\-sslFIPSMode New in version 2.6. .sp Directs the \fBmongoimport\fP to use the FIPS mode of the TLS/SSL library. Your system must have a FIPS compliant library to use the \fI\%\-\-sslFIPSMode\fP option. .sp \fBNOTE:\fP .INDENT 7.0 .INDENT 3.5 FIPS\-compatible TLS/SSL is available only in \fI\%MongoDB Enterprise\fP\&. See /tutorial/configure\-fips for more information. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B \-\-username , \-u 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 , \-p 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 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 \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 , \-d 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 , \-c 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 , \-f 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 To also specify the field type as well as the field name, use \fI\%\-\-fields\fP with \fI\%\-\-columnsHaveTypes\fP\&. .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 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 To also specify the field type as well as the field name, use \fI\%\-\-fieldFile\fP with \fI\%\-\-columnsHaveTypes\fP\&. .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 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 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 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 \-\-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 \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\&. For example: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C \-\-writeConcern "{w:\(aqmajority\(aq}" .ft P .fi .UNINDENT .UNINDENT .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.()\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()\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()\fP T} T{ Alias for \fBdate_go()\fP\&. \fI\%Go Language time.Parse format\fP\&. T} T{ \fBcreated.date(2006\-01\-02 15:04:05)\fP T} _ T{ \fBdate_go()\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()\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()\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 \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 Starting in MongoDB 3.4, when you specify the field name, you can also specify the data type. To specify field names and type, include \fI\%\-\-columnsHaveTypes\fP with either: \fI\%\-\-fields\fP, \fI\%\-\-fieldFile\fP, or \fI\%\-\-headerline\fP\&. .sp Specify field names and data types in the form \fB.()\fP\&. .sp For example, a \fB/example/file.csv\fP file contains the following data: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C Katherine Gray, 1996\-02\-03, false, 1235, TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlzIG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBpbiByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xvcmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNhdCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lhIGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg== Albert Gilbert, 1992\-04\-24, true, 13, Q3VwY2FrZSBpcHN1bSBkb2xvciBzaXQgYW1ldCB0b290c2llIHJvbGwgYm9uYm9uIHRvZmZlZS4gQ2FuZHkgY2FuZXMgcGllIGNyb2lzc2FudCBjaG9jb2xhdGUgYmFyIGxvbGxpcG9wIGJlYXIgY2xhdyBtYWNhcm9vbi4gU3dlZXQgcm9sbCBjdXBjYWtlIGNoZWVzZWNha2Ugc291ZmZsw6kgYnJvd25pZSBpY2UgY3JlYW0uIEp1anViZXMgY2FrZSBjdXBjYWtlIG1hY2Fyb29uIGRhbmlzaCBqZWxseS1vIHNvdWZmbMOpLiBDYWtlIGFwcGxlIHBpZSBnaW5nZXJicmVhZCBjaG9jb2xhdGUgc3VnYXIgcGx1bS4gU3dlZXQgY2hvY29sYXRlIGNha2UgY2hvY29sYXRlIGNha2UganVqdWJlcyB0aXJhbWlzdSBvYXQgY2FrZS4gU3dlZXQgc291ZmZsw6kgY2hvY29sYXRlLiBMaXF1b3JpY2UgY290dG9uIGNhbmR5IGNob2NvbGF0ZSBtYXJzaG1hbGxvdy4gSmVsbHkgY29va2llIGNha2UgamVsbHkgYm== .ft P .fi .UNINDENT .UNINDENT .sp The following operation uses \fI\%mongoimport\fP with the \fI\%\-\-fields\fP and \fI\%\-\-columnsHaveTypes\fP option to specify both the field names and the BSON types of the imported CSV data. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C mongoimport \e \-\-db users \e \-\-collection contacts \e \-\-type csv \e \-\-columnsHaveTypes \e \-\-fields \e "name.string(),\e birthdate.date(2006\-01\-02),\e contacted.boolean(),\e followerCount.int32(),\e thumbnail.binary(base64)" \e \-\-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. .