1MONGOIMPORT(1)                  mongodb-manual                  MONGOIMPORT(1)
2
3
4

NAME

6       mongoimport - MongoDB Import Utility
7

SYNOPSIS

9       The  mongoimport  tool  provides a route to import content from a JSON,
10       CSV, or TSV export created  by  mongoexport,  or  potentially,  another
11       third-party   export   tool.   See   the   http://docs.mongodb.org/man
12       ual/core/import-export document for a more in depth usage overview, and
13       the  mongoexport  document  for more information regarding mongoexport,
14       which provides the inverse "exporting" capability.
15

CONSIDERATIONS

17       Do not use mongoimport and mongoexport for  full  instance,  production
18       backups  because  they will not reliably capture data type information.
19       Use  mongodump  and  mongorestore  as  described  in   http://docs.mon
20       godb.org/manual/core/backups for this kind of functionality.
21
22       mongoimport  is single-threaded and inserts one document at a time into
23       MongoDB. Custom import tools for data ingestion may have better perfor‐
24       mance for specific workloads.
25

OPTIONS

27       Changed  in  version 3.0.0: mongoimport removed the --dbpath as well as
28       related --directoryperdb and --journal options. You must  use  mongoim‐
29       port while connected to a mongod instance.
30
31
32       mongoimport
33
34       mongoimport
35
36       --help Returns information on the options and use of mongoimport.
37
38       --verbose, -v
39              Increases  the amount of internal reporting returned on standard
40              output or in log files. Increase the verbosity with the -v  form
41              by including the option multiple times, (e.g. -vvvvv.)
42
43       --quiet
44              Runs  the mongoimport in a quiet mode that attempts to limit the
45              amount of output.
46
47              This option suppresses:
48
49              · output from database commands
50
51              · replication activity
52
53              · connection accepted events
54
55              · connection closed events
56
57       --version
58              Returns the mongoimport release number.
59
60       --host <hostname><:port>, -h <hostname><:port>
61              Default: localhost:27017
62
63              Specifies a resolvable hostname for the mongod to which to  con‐
64              nect.  By default, the mongoimport attempts to connect to a Mon‐
65              goDB instance running on the localhost on port number 27017.
66
67              To connect to a replica set, specify the replSetName and a  seed
68              list of set members, as in the following:
69
70                 <replSetName>/<hostname1><:port>,<hostname2><:port>,<...>
71
72              You  can always connect directly to a single MongoDB instance by
73              specifying the host and port number directly.
74
75              Changed  in  version  3.0.0:  If  you  use  IPv6  and  use   the
76              <address>:<port>  format,  you  must  enclose  the portion of an
77              address and port combination in brackets (e.g. [<address>]).
78
79
80       --port <port>
81              Default: 27017
82
83              Specifies the TCP port on which the MongoDB instance listens for
84              client connections.
85
86       --ipv6 Enables  IPv6  support  and allows the mongoimport to connect to
87              the MongoDB instance using an IPv6 network. All MongoDB programs
88              and processes disable IPv6 support by default.
89
90       --ssl  New in version 2.6.
91
92
93              Enables  connection  to  a mongod or mongos that has SSL support
94              enabled.
95
96              The default distribution of MongoDB does not contain support for
97              SSL.    For   more   information   on   MongoDB   and  SSL,  see
98              http://docs.mongodb.org/manual/tutorial/configure-ssl.
99
100       --sslCAFile <filename>
101              New in version 2.6.
102
103
104              Specifies the .pem file that contains the root certificate chain
105              from  the  Certificate  Authority.  Specify the file name of the
106              .pem file using relative or absolute paths.
107
108              The default distribution of MongoDB does not contain support for
109              SSL.    For   more   information   on   MongoDB   and  SSL,  see
110              http://docs.mongodb.org/manual/tutorial/configure-ssl.
111
112              WARNING:
113                 If the mongo shell or any other tool that connects to  mongos
114                 or  mongod is run without --sslCAFile, it will not attempt to
115                 validate server certificates. This results  in  vulnerability
116                 to  expired mongod and mongos certificates as well as to for‐
117                 eign processes posing as valid mongod  or  mongos  instances.
118                 Ensure  that  you  always  specify  the CA file against which
119                 server certificates should be validated in cases where intru‐
120                 sion is a possibility.
121
122       --sslPEMKeyFile <filename>
123              New in version 2.6.
124
125
126              Specifies  the  .pem file that contains both the SSL certificate
127              and key. Specify the file name of the .pem file  using  relative
128              or absolute paths.
129
130              This  option  is required when using the --ssl option to connect
131              to a mongod or mongos that has CAFile enabled without  allowCon‐
132              nectionsWithoutCertificates.
133
134              The default distribution of MongoDB does not contain support for
135              SSL.   For  more   information   on   MongoDB   and   SSL,   see
136              http://docs.mongodb.org/manual/tutorial/configure-ssl.
137
138       --sslPEMKeyPassword <value>
139              New in version 2.6.
140
141
142              Specifies  the  password  to  de-crypt  the certificate-key file
143              (i.e.  --sslPEMKeyFile). Use the --sslPEMKeyPassword option only
144              if the certificate-key file is encrypted. In all cases, the mon‐
145              goimport will redact the password from all logging and reporting
146              output.
147
148              If  the  private key in the PEM file is encrypted and you do not
149              specify the --sslPEMKeyPassword  option,  the  mongoimport  will
150              prompt for a passphrase. See ssl-certificate-password.
151
152              The default distribution of MongoDB does not contain support for
153              SSL.   For  more   information   on   MongoDB   and   SSL,   see
154              http://docs.mongodb.org/manual/tutorial/configure-ssl.
155
156       --sslCRLFile <filename>
157              New in version 2.6.
158
159
160              Specifies the .pem file that contains the Certificate Revocation
161              List. Specify the file name of the .pem file using  relative  or
162              absolute paths.
163
164              The default distribution of MongoDB does not contain support for
165              SSL.   For  more   information   on   MongoDB   and   SSL,   see
166              http://docs.mongodb.org/manual/tutorial/configure-ssl.
167
168       --sslAllowInvalidCertificates
169              New in version 2.6.
170
171
172              Bypasses  the  validation  checks  for  server  certificates and
173              allows the use of invalid certificates. When using the  allowIn‐
174              validCertificates  setting, MongoDB logs as a warning the use of
175              the invalid certificate.
176
177              The default distribution of MongoDB does not contain support for
178              SSL.    For   more   information   on   MongoDB   and  SSL,  see
179              http://docs.mongodb.org/manual/tutorial/configure-ssl.
180
181       --sslAllowInvalidHostnames
182              New in version 3.0.
183
184
185              Disables the validation of the hostnames  in  SSL  certificates.
186              Allows  mongoimport to connect to MongoDB instances if the host‐
187              name their certificates do not match the specified hostname.
188
189       --sslFIPSMode
190              New in version 2.6.
191
192
193              Directs the mongoimport to use the FIPS mode  of  the  installed
194              OpenSSL  library. Your system must have a FIPS compliant OpenSSL
195              library to use the --sslFIPSMode option.
196
197              NOTE:
198                 FIPS Compatible SSL is available only in MongoDB  Enterprise.
199                 See    http://docs.mongodb.org/manual/tutorial/configure-fips
200                 for more information.
201
202       --username <username>, -u <username>
203              Specifies a username with which to  authenticate  to  a  MongoDB
204              database  that  uses authentication. Use in conjunction with the
205              --password and --authenticationDatabase options.
206
207       --password <password>, -p <password>
208              Specifies a password with which to  authenticate  to  a  MongoDB
209              database  that  uses authentication. Use in conjunction with the
210              --username and --authenticationDatabase options.
211
212              If you do not specify an argument  for  --password,  mongoimport
213              will prompt interactively for a password on the console.
214
215       --authenticationDatabase <dbname>
216              New in version 2.4.
217
218
219              Specifies the database that holds the user's credentials.
220
221       --authenticationMechanism <name>
222              Default: MONGODB-CR
223
224              New in version 2.4.
225
226
227              Changed  in  version  2.6:  Added support for the PLAIN and MON‐
228              GODB-X509 authentication mechanisms.
229
230
231              Specifies the authentication mechanism the mongoimport  instance
232              uses to authenticate to the mongod or mongos.
233
234                        ┌─────────────┬────────────────────────────┐
235                        │Value        │ Description                │
236                        ├─────────────┼────────────────────────────┤
237                        │MONGODB-CR   │ MongoDB challenge/response │
238                        │             │ authentication.            │
239                        ├─────────────┼────────────────────────────┤
240                        │MONGODB-X509 │ MongoDB  SSL   certificate │
241                        │             │ authentication.            │
242                        ├─────────────┼────────────────────────────┤
243                        │PLAIN        │ External    authentication │
244                        │             │ using LDAP. You  can  also │
245                        │             │ use PLAIN for authenticat‐ │
246                        │             │ ing   in-database   users. │
247                        │             │ PLAIN  transmits passwords │
248                        │             │ in plain text. This mecha‐ │
249                        │             │ nism  is available only in │
250                        │             │ MongoDB Enterprise.        │
251                        ├─────────────┼────────────────────────────┤
252                        │GSSAPI       │ External    authentication │
253                        │             │ using Kerberos. This mech‐ │
254                        │             │ anism is available only in │
255                        │             │ MongoDB Enterprise.        │
256                        └─────────────┴────────────────────────────┘
257
258       --gssapiServiceName
259              New in version 2.6.
260
261
262              Specify  the  name  of  the  service using GSSAPI/Kerberos. Only
263              required if the service does not use the default  name  of  mon‐
264              godb.
265
266              This option is available only in MongoDB Enterprise.
267
268       --gssapiHostName
269              New in version 2.6.
270
271
272              Specify  the  hostname  of a service using GSSAPI/Kerberos. Only
273              required if the hostname of a machine does not match  the  host‐
274              name resolved by DNS.
275
276              This option is available only in MongoDB Enterprise.
277
278       --db <database>, -d <database>
279              Specifies  the name of the database on which to run the mongoim‐
280              port.
281
282       --collection <collection>, -c <collection>
283              Specifies the collection to import.
284
285              New in version 2.6: If you do not specify --collection, mongoim‐
286              port  takes the collection name from the input filename. MongoDB
287              omits the extension of the file from the collection name, if the
288              input file has an extension.
289
290
291       --fields <field1[,field2]>, -f <field1[,field2]>
292              Specify a comma separated list of field names when importing csv
293              or tsv files that do not have field names  in  the  first  (i.e.
294              header) line of the file.
295
296              If  you  attempt  to  include --fields when importing JSON data,
297              mongoimport will return an error. --fields is only  for  csv  or
298              tsv imports.
299
300       --fieldFile <filename>
301              As an alternative to --fields, the --fieldFile option allows you
302              to specify a file that holds a list of field names if  your  csv
303              or  tsv  file  does not include field names in the first line of
304              the file (i.e. header). Place one field per line.
305
306              If you attempt to include --fieldFile when importing JSON  data,
307              mongoimport will return an error. --fieldFile is only for csv or
308              tsv imports.
309
310       --ignoreBlanks
311              Ignores empty fields in csv and tsv exports. If  not  specified,
312              mongoimport creates fields without values in imported documents.
313
314              If  you  attempt  to  include --ignoreBlanks when importing JSON
315              data, mongoimport will return an error. --ignoreBlanks  is  only
316              for csv or tsv imports.
317
318       --type <json|csv|tsv>
319              Specifies  the  file type to import. The default format is JSON,
320              but it's possible to import csv and tsv files.
321
322              The csv parser accepts that data  that  complies  with  RFC  RFC
323              4180. As a result, backslashes are not a valid escape character.
324              If you use double-quotes to enclose fields in the CSV data,  you
325              must  escape  internal  double-quote marks by prepending another
326              double-quote.
327
328       --file <filename>
329              Specifies the location and name of a file containing the data to
330              import.   If  you  do not specify a file, mongoimport reads data
331              from standard input (e.g. "stdin").
332
333       --drop Modifies the import process so that the  target  instance  drops
334              the collection before importing the data from the input.
335
336       --headerline
337              If  using --type csv or --type tsv, uses the first line as field
338              names.  Otherwise, mongoimport will import the first line  as  a
339              distinct document.
340
341              If you attempt to include --headerline when importing JSON data,
342              mongoimport will return an error. --headerline is only  for  csv
343              or tsv imports.
344
345       --upsert
346              Modifies  the  import  process to update existing objects in the
347              database if they match an imported object, while  inserting  all
348              other objects.
349
350              If you do not specify a field or fields using the --upsertFields
351              mongoimport will upsert on the basis of the _id field.
352
353              ..versionchanged:: 3.0.0
354                     --upsert is no longer needed when specifying upserts. Use
355                     --upsertFields, which produces the same behavior.
356
357       --upsertFields <field1[,field2]>
358              Specifies  a list of fields for the query portion of the upsert.
359              Use this option if the _id  fields  in  the  existing  documents
360              don't  match  the  field  in  the document, but another field or
361              field combination can uniquely identify documents as a basis for
362              performing upsert operations.
363
364              ..versionchanged:: 3.0.0
365                     Modifies the import process to update existing objects in
366                     the database if they match based on the specified fields,
367                     while inserting all other objects.
368
369                     If you do not specify a field, --upsertFields will upsert
370                     on the basis of the _id field.
371
372              To ensure adequate performance, indexes should  exist  for  this
373              field or fields.
374
375       --stopOnError
376              New in version 2.2.
377
378
379              Forces  mongoimport  to  halt  the import operation at the first
380              error rather than continuing the operation despite errors.
381
382              Changed in version 3.0.0: --stopOnError  interrupts  the  import
383              operation when mongoimport encounters an insert or upsert error.
384              Other error types will not stop the import.
385
386
387       --jsonArray
388              Accepts the import of data expressed with multiple MongoDB docu‐
389              ments within a single JSON array. Limited to imports of 16 MB or
390              smaller.
391
392              Use --jsonArray in conjunction with mongoexport --jsonArray.
393
394       --maintainInsertionOrder
395              Default: False
396
397              If specified, mongoimport inserts the documents in the order  of
398              their  appearance in the input source, otherwise mongoimport may
399              perform the insertions in an arbitrary order.
400
401       --writeConcern <document>
402              Default: majority
403
404              Specifies the write concern for each write operation  that  mon‐
405              goimport writes to the target database.
406
407              Specify the write concern as a document with w options.
408

USE

410       In  this  example,  mongoimport  imports  the csv formatted data in the
411       /opt/backups/contacts.csv into the collection  contacts  in  the  users
412       database on the MongoDB instance running on the localhost port numbered
413       27017. mongoimport determines the name of files using the first line in
414       the CSV file, because of the --headerline:
415
416          mongoimport --db users --collection contacts --type csv --headerline --file /opt/backups/contacts.csv
417
418       Since  mongoimport  uses the input file name, without the extension, as
419       the collection name if -c or --collection is unspecified. The following
420       example is equivalent:
421
422          mongoimport --db users --type csv --headerline --file /opt/backups/contacts.csv
423
424       In the following example, mongoimport imports the data in the JSON for‐
425       matted file contacts.json into the collection contacts on  the  MongoDB
426       instance running on the localhost port number 27017.
427
428          mongoimport --db users --collection contacts --file contacts.json
429
430       In  the next example, mongoimport imports data from the file /opt/back‐
431       ups/mdb1-examplenet.json into the collection contacts within the  data‐
432       base  marketing on a remote MongoDB database. This mongoimport accesses
433       the mongod instance running on the host mongodb1.example.net over  port
434       37017, which requires the username user and the password pass.
435
436          mongoimport --host mongodb1.example.net --port 37017 --username user --password pass --collection contacts --db marketing --file /opt/backups/mdb1-examplenet.json
437

TYPE FIDELITY

439       WARNING:
440          mongoimport  and  mongoexport do not reliably preserve all rich BSON
441          data types because JSON can only represent a  subset  of  the  types
442          supported by BSON. As a result, data exported or imported with these
443          tools may lose some measure of fidelity. See the Extended JSON  ref‐
444          erence for more information.
445
446       JSON  can  only  represent  a subset of the types supported by BSON. To
447       preserve type information, mongoimport accepts strict mode  representa‐
448       tion for certain types.
449
450       For  example, to preserve type information for BSON types data_date and
451       data_numberlong during mongoimport, the data should be in  strict  mode
452       representation, as in the following:
453
454          { "_id" : 1, "volume" : { "$numberLong" : "2980000" }, "date" : { "$date" : "2014-03-13T13:47:42.483-0400" } }
455
456       For  the data_numberlong type, mongoimport converts into a float during
457       the import.
458
459       See http://docs.mongodb.org/manual/reference/mongodb-extended-json  for
460       a complete list of these types and the representations used.
461

AUTHOR

463       MongoDB Documentation Project
464
466       2011-2015
467
468
469
470
4713.0                            January 30, 2015                 MONGOIMPORT(1)
Impressum