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

NAME

6       mongoexport - MongoDB Export Utility
7

SYNOPSIS

9       mongoexport  is  a  utility  that produces a JSON or CSV export of data
10       stored in a  MongoDB  instance.  See  the  http://docs.mongodb.org/man
11       ual/core/import-export document for a more in depth usage overview, and
12       the mongoimport document for more information regarding the mongoimport
13       utility, which provides the inverse "importing" capability.
14

CONSIDERATIONS

16       Do  not use mongoimport and mongoexport for full-scale production back‐
17       ups because they may not reliably capture data  type  information.  Use
18       mongodump and mongorestore as described in http://docs.mongodb.org/man
19       ual/core/backups for this kind of functionality.
20

OPTIONS

22       Changed in version 3.0.0: mongoexport removed the --dbpath as  well  as
23       related  --directoryperdb  and --journal options. You must use mongoex‐
24       port while connected to a mongod instance.
25
26
27       Changed in version 3.0.0: mongoexport also removed support for  writing
28       data to tsv files with the --tsv option.
29
30
31       mongoexport
32
33       mongoexport
34
35       --help Returns information on the options and use of mongoexport.
36
37       --verbose, -v
38              Increases  the amount of internal reporting returned on standard
39              output or in log files. Increase the verbosity with the -v  form
40              by including the option multiple times, (e.g. -vvvvv.)
41
42       --quiet
43              Runs  the mongoexport in a quiet mode that attempts to limit the
44              amount of output.
45
46              This option suppresses:
47
48              · output from database commands
49
50              · replication activity
51
52              · connection accepted events
53
54              · connection closed events
55
56       --version
57              Returns the mongoexport release number.
58
59       --host <hostname><:port>, -h <hostname><:port>
60              Default: localhost:27017
61
62              Specifies a resolvable hostname for the mongod to which to  con‐
63              nect.  By default, the mongoexport attempts to connect to a Mon‐
64              goDB instance running on the localhost on port number 27017.
65
66              To connect to a replica set, specify the replSetName and a  seed
67              list of set members, as in the following:
68
69                 <replSetName>/<hostname1><:port>,<hostname2><:port>,<...>
70
71              You  can always connect directly to a single MongoDB instance by
72              specifying the host and port number directly.
73
74              Changed  in  version  3.0.0:  If  you  use  IPv6  and  use   the
75              <address>:<port>  format,  you  must  enclose  the portion of an
76              address and port combination in brackets (e.g. [<address>]).
77
78
79       --port <port>
80              Default: 27017
81
82              Specifies the TCP port on which the MongoDB instance listens for
83              client connections.
84
85       --ipv6 Enables  IPv6  support  and allows the mongoexport to connect to
86              the MongoDB instance using an IPv6 network. All MongoDB programs
87              and processes disable IPv6 support by default.
88
89       --ssl  New in version 2.6.
90
91
92              Enables  connection  to  a mongod or mongos that has SSL support
93              enabled.
94
95              The default distribution of MongoDB does not contain support for
96              SSL.    For   more   information   on   MongoDB   and  SSL,  see
97              http://docs.mongodb.org/manual/tutorial/configure-ssl.
98
99       --sslCAFile <filename>
100              New in version 2.6.
101
102
103              Specifies the .pem file that contains the root certificate chain
104              from  the  Certificate  Authority.  Specify the file name of the
105              .pem file using relative or absolute paths.
106
107              The default distribution of MongoDB does not contain support for
108              SSL.    For   more   information   on   MongoDB   and  SSL,  see
109              http://docs.mongodb.org/manual/tutorial/configure-ssl.
110
111              WARNING:
112                 If the mongo shell or any other tool that connects to  mongos
113                 or  mongod is run without --sslCAFile, it will not attempt to
114                 validate server certificates. This results  in  vulnerability
115                 to  expired mongod and mongos certificates as well as to for‐
116                 eign processes posing as valid mongod  or  mongos  instances.
117                 Ensure  that  you  always  specify  the CA file against which
118                 server certificates should be validated in cases where intru‐
119                 sion is a possibility.
120
121       --sslPEMKeyFile <filename>
122              New in version 2.6.
123
124
125              Specifies  the  .pem file that contains both the SSL certificate
126              and key. Specify the file name of the .pem file  using  relative
127              or absolute paths.
128
129              This  option  is required when using the --ssl option to connect
130              to a mongod or mongos that has CAFile enabled without  allowCon‐
131              nectionsWithoutCertificates.
132
133              The default distribution of MongoDB does not contain support for
134              SSL.   For  more   information   on   MongoDB   and   SSL,   see
135              http://docs.mongodb.org/manual/tutorial/configure-ssl.
136
137       --sslPEMKeyPassword <value>
138              New in version 2.6.
139
140
141              Specifies  the  password  to  de-crypt  the certificate-key file
142              (i.e.  --sslPEMKeyFile). Use the --sslPEMKeyPassword option only
143              if the certificate-key file is encrypted. In all cases, the mon‐
144              goexport will redact the password from all logging and reporting
145              output.
146
147              If  the  private key in the PEM file is encrypted and you do not
148              specify the --sslPEMKeyPassword  option,  the  mongoexport  will
149              prompt for a passphrase. See ssl-certificate-password.
150
151              The default distribution of MongoDB does not contain support for
152              SSL.   For  more   information   on   MongoDB   and   SSL,   see
153              http://docs.mongodb.org/manual/tutorial/configure-ssl.
154
155       --sslCRLFile <filename>
156              New in version 2.6.
157
158
159              Specifies the .pem file that contains the Certificate Revocation
160              List. Specify the file name of the .pem file using  relative  or
161              absolute paths.
162
163              The default distribution of MongoDB does not contain support for
164              SSL.   For  more   information   on   MongoDB   and   SSL,   see
165              http://docs.mongodb.org/manual/tutorial/configure-ssl.
166
167       --sslAllowInvalidCertificates
168              New in version 2.6.
169
170
171              Bypasses  the  validation  checks  for  server  certificates and
172              allows the use of invalid certificates. When using the  allowIn‐
173              validCertificates  setting, MongoDB logs as a warning the use of
174              the invalid certificate.
175
176              The default distribution of MongoDB does not contain support for
177              SSL.    For   more   information   on   MongoDB   and  SSL,  see
178              http://docs.mongodb.org/manual/tutorial/configure-ssl.
179
180       --sslAllowInvalidHostnames
181              New in version 3.0.
182
183
184              Disables the validation of the hostnames  in  SSL  certificates.
185              Allows  mongoexport to connect to MongoDB instances if the host‐
186              name their certificates do not match the specified hostname.
187
188       --sslFIPSMode
189              New in version 2.6.
190
191
192              Directs the mongoexport to use the FIPS mode  of  the  installed
193              OpenSSL  library. Your system must have a FIPS compliant OpenSSL
194              library to use the --sslFIPSMode option.
195
196              NOTE:
197                 FIPS Compatible SSL is available only in MongoDB  Enterprise.
198                 See    http://docs.mongodb.org/manual/tutorial/configure-fips
199                 for more information.
200
201       --username <username>, -u <username>
202              Specifies a username with which to  authenticate  to  a  MongoDB
203              database  that  uses authentication. Use in conjunction with the
204              --password and --authenticationDatabase options.
205
206       --password <password>, -p <password>
207              Specifies a password with which to  authenticate  to  a  MongoDB
208              database  that  uses authentication. Use in conjunction with the
209              --username and --authenticationDatabase options.
210
211              If you do not specify an argument  for  --password,  mongoexport
212              will prompt interactively for a password on the console.
213
214       --authenticationDatabase <dbname>
215              If  you  do  not specify an authentication database, mongoexport
216              assumes that the database specified to export holds  the  user's
217              credentials.
218
219       --authenticationMechanism <name>
220              Default: MONGODB-CR
221
222              New in version 2.4.
223
224
225              Changed  in  version  2.6:  Added support for the PLAIN and MON‐
226              GODB-X509 authentication mechanisms.
227
228
229              Specifies the authentication mechanism the mongoexport  instance
230              uses to authenticate to the mongod or mongos.
231
232                        ┌─────────────┬────────────────────────────┐
233                        │Value        │ Description                │
234                        ├─────────────┼────────────────────────────┤
235                        │MONGODB-CR   │ MongoDB challenge/response │
236                        │             │ authentication.            │
237                        ├─────────────┼────────────────────────────┤
238                        │MONGODB-X509 │ MongoDB  SSL   certificate │
239                        │             │ authentication.            │
240                        ├─────────────┼────────────────────────────┤
241                        │PLAIN        │ External    authentication │
242                        │             │ using LDAP. You  can  also │
243                        │             │ use PLAIN for authenticat‐ │
244                        │             │ ing   in-database   users. │
245                        │             │ PLAIN  transmits passwords │
246                        │             │ in plain text. This mecha‐ │
247                        │             │ nism  is available only in │
248                        │             │ MongoDB Enterprise.        │
249                        ├─────────────┼────────────────────────────┤
250                        │GSSAPI       │ External    authentication │
251                        │             │ using Kerberos. This mech‐ │
252                        │             │ anism is available only in │
253                        │             │ MongoDB Enterprise.        │
254                        └─────────────┴────────────────────────────┘
255
256       --gssapiServiceName
257              New in version 2.6.
258
259
260              Specify  the  name  of  the  service using GSSAPI/Kerberos. Only
261              required if the service does not use the default  name  of  mon‐
262              godb.
263
264              This option is available only in MongoDB Enterprise.
265
266       --gssapiHostName
267              New in version 2.6.
268
269
270              Specify  the  hostname  of a service using GSSAPI/Kerberos. Only
271              required if the hostname of a machine does not match  the  host‐
272              name resolved by DNS.
273
274              This option is available only in MongoDB Enterprise.
275
276       --db <database>, -d <database>
277              Specifies  the name of the database on which to run the mongoex‐
278              port.
279
280       --collection <collection>, -c <collection>
281              Specifies the collection to export.
282
283       --fields <field1[,field2]>, -f <field1[,field2]>
284              Specifies a field or fields to include  in  the  export.  Use  a
285              comma separated list of fields to specify multiple fields.
286
287              For  csv output formats, mongoexport includes only the specified
288              field(s), and the specified field(s) can be  a  field  within  a
289              sub-document.
290
291              For JSON output formats, mongoexport includes only the specified
292              field(s) and the _id field, and if the specified field(s)  is  a
293              field  within  a  sub-document,  the  mongoexport  includes  the
294              sub-document with all its fields, not just the  specified  field
295              within the document.
296
297       --fieldFile <filename>
298              An alternative to --fields. The --fieldFile option allows you to
299              specify in a file the field or fields to include in  the  export
300              and  is  only  valid  with the --type option with value csv. The
301              file must have only one field per line, and the line(s) must end
302              with the LF character (0x0A).
303
304              mongoexport  includes only the specified field(s). The specified
305              field(s) can be a field within a sub-document.
306
307       --query <JSON>, -q <JSON>
308              Provides a JSON document as a query that optionally  limits  the
309              documents returned in the export. Specify JSON in strict format.
310
311              For  example,  given  a collection named records in the database
312              test with the following documents:
313
314                 { "_id" : ObjectId("51f0188846a64a1ed98fde7c"), "a" : 1 }
315                 { "_id" : ObjectId("520e61b0c6646578e3661b59"), "a" : 1, "b" : 2 }
316                 { "_id" : ObjectId("520e642bb7fa4ea22d6b1871"), "a" : 2, "b" : 3, "c" : 5 }
317                 { "_id" : ObjectId("520e6431b7fa4ea22d6b1872"), "a" : 3, "b" : 3, "c" : 6 }
318                 { "_id" : ObjectId("520e6445b7fa4ea22d6b1873"), "a" : 5, "b" : 6, "c" : 8 }
319
320              The following mongoexport uses the -q option to export only  the
321              documents with the field a greater than or equal to ($gte) to 3:
322
323                 mongoexport -d test -c records -q "{ a: { \$gte: 3 } }" --out exportdir/myRecords.json
324
325              The resulting file contains the following documents:
326
327                 { "_id" : { "$oid" : "520e6431b7fa4ea22d6b1872" }, "a" : 3, "b" : 3, "c" : 6 }
328                 { "_id" : { "$oid" : "520e6445b7fa4ea22d6b1873" }, "a" : 5, "b" : 6, "c" : 8 }
329
330              You can sort the results with the --sort option to mongoexport.
331
332       --type <string>
333              Default: json
334
335              New in version 3.0.0.
336
337
338              Specifies  the  file type to export. The default format is JSON,
339              bit it is possible to export csv files.
340
341              If you specify csv, then you must also use either  the  --fields
342              or  the  --fieldFile option to declare the fields to export from
343              the collection.
344
345       --out <file>, -o <file>
346              Specifies a file to write the export to. If you do not specify a
347              file  name, the mongoexport writes data to standard output (e.g.
348              stdout).
349
350       --jsonArray
351              Modifies the output of mongoexport to write the entire  contents
352              of  the  export  as  a single JSON array. By default mongoexport
353              writes data using one JSON document for every MongoDB document.
354
355       --pretty
356              New in version 3.0.0.
357
358
359              Outputs documents in a pretty-printed format JSON.
360
361       --slaveOk, -k
362              Allows mongoexport to read data from secondary  or  slave  nodes
363              when  using  mongoexport with a replica set. This option is only
364              available if connected to a mongod or mongos and is  not  avail‐
365              able when used with the "mongoexport --dbpath" option.
366
367              This is the default behavior.
368
369       --forceTableScan
370              New in version 2.2.
371
372
373              Forces  mongoexport  to scan the data store directly: typically,
374              mongoexport saves entries as they appear in the index of the _id
375              field.  Use --forceTableScan to skip the index and scan the data
376              directly. Typically there are two cases where this  behavior  is
377              preferable to the default:
378
379              1. If  you  have  key  sizes  over  800  bytes that would not be
380                 present in the _id index.
381
382              2. Your database uses a custom _id field.
383
384              When you run with --forceTableScan,  mongoexport  does  not  use
385              $snapshot.  As  a result, the export produced by mongoexport can
386              reflect the state of the database at many  different  points  in
387              time.
388
389              WARNING:
390                 Use --forceTableScan with extreme caution and consideration.
391
392       --skip <number>
393              Use  --skip  to control where mongoexport begins exporting docu‐
394              ments. See skip() for information about  the  underlying  opera‐
395              tion.
396
397       --limit <number>
398              Specifies  a  maximum  number  of  documents  to  include in the
399              export. See limit() for information about the underlying  opera‐
400              tion.
401
402       --sort <JSON>
403              Specifies an ordering for exported results. If an index does not
404              exist that can support the sort operation, the results  must  be
405              less than 32 megabytes.
406
407              Use  --sort  conjunction with --skip and --limit to limit number
408              of exported documents.
409
410                 mongoexport -d test -c records --sort '{a: 1}' --limit 100 --out export.0.json
411                 mongoexport -d test -c records --sort '{a: 1}' --limit 100 --skip 100 --out export.1.json
412                 mongoexport -d test -c records --sort '{a: 1}' --limit 100 --skip 200 --out export.2.json
413
414              See sort() for information about the underlying operation.
415

USE

417   Export in CSV Format
418       In the following example, mongoexport exports the  collection  contacts
419       from  the users database from the mongod instance running on the local‐
420       host port number 27017. This command writes the export data in CSV for‐
421       mat  into  a file located at /opt/backups/contacts.csv.  The fields.txt
422       file contains a line-separated list of fields to export.
423
424          mongoexport --db users --collection contacts --csv --fieldFile fields.txt --out /opt/backups/contacts.csv
425
426   Export in JSON Format
427       The next example creates an export of the collection contacts from  the
428       MongoDB instance running on the localhost port number 27017, with jour‐
429       naling explicitly enabled. This writes the export to the  contacts.json
430       file in JSON format.
431
432          mongoexport --db sales --collection contacts --out contacts.json --journal
433
434   Export from Remote Host Running with Authentication
435       The following example exports the collection contacts from the database
436       marketing . This data resides on the MongoDB instance  located  on  the
437       host  mongodb1.example.net  running  on  port 37017, which requires the
438       username user and the password pass.
439
440          mongoexport --host mongodb1.example.net --port 37017 --username user --password pass --collection contacts --db marketing --out mdb1-examplenet.json
441

TYPE FIDELITY

443       WARNING:
444          mongoimport and mongoexport do not reliably preserve all  rich  BSON
445          data  types  because  JSON  can only represent a subset of the types
446          supported by BSON. As a result, data exported or imported with these
447          tools  may lose some measure of fidelity. See the Extended JSON ref‐
448          erence for more information.
449
450       JSON can only represent a subset of the types  supported  by  BSON.  To
451       preserve type information, mongoexport uses the strict mode representa‐
452       tion for certain types.
453
454       For example, the following insert operation in the mongo shell uses the
455       mongoShell  mode  representation  for  the  BSON  types  data_date  and
456       data_numberlong:
457
458          use test
459          db.traffic.insert( { _id: 1, volume: NumberLong(2980000), date: new Date() } )
460
461       Use mongoexport to export the data:
462
463          mongoexport --db test --collection traffic --out traffic.json
464
465       The exported data is in strict mode  representation  to  preserve  type
466       information:
467
468          { "_id" : 1, "volume" : { "$numberLong" : "2980000" }, "date" : { "$date" : "2014-03-13T13:47:42.483-0400" } }
469
470       See  http://docs.mongodb.org/manual/reference/mongodb-extended-json for
471       a complete list of these types and the representations used.
472

AUTHOR

474       MongoDB Documentation Project
475
477       2011-2015
478
479
480
481
4823.0                            January 30, 2015                 MONGOEXPORT(1)
Impressum