Blame SOURCES/mongoexport.1

7fe184
.\" Man page generated from reStructuredText.
7fe184
.
7fe184
.TH "MONGOEXPORT" "1" "January 30, 2015" "3.0" "mongodb-manual"
7fe184
.SH NAME
7fe184
mongoexport \- MongoDB Export Utility
7fe184
.
7fe184
.nr rst2man-indent-level 0
7fe184
.
7fe184
.de1 rstReportMargin
7fe184
\\$1 \\n[an-margin]
7fe184
level \\n[rst2man-indent-level]
7fe184
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
7fe184
-
7fe184
\\n[rst2man-indent0]
7fe184
\\n[rst2man-indent1]
7fe184
\\n[rst2man-indent2]
7fe184
..
7fe184
.de1 INDENT
7fe184
.\" .rstReportMargin pre:
7fe184
. RS \\$1
7fe184
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
7fe184
. nr rst2man-indent-level +1
7fe184
.\" .rstReportMargin post:
7fe184
..
7fe184
.de UNINDENT
7fe184
. RE
7fe184
.\" indent \\n[an-margin]
7fe184
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
7fe184
.nr rst2man-indent-level -1
7fe184
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
7fe184
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
7fe184
..
7fe184
.SH SYNOPSIS
7fe184
.sp
7fe184
\fBmongoexport\fP is a utility that produces a JSON or CSV export
7fe184
of data stored in a MongoDB instance. See the
7fe184
http://docs.mongodb.org/manual/core/import\-export document for a more in depth
7fe184
usage overview, and the \fBmongoimport\fP document for more
7fe184
information regarding the \fBmongoimport\fP utility, which
7fe184
provides the inverse "importing" capability.
7fe184
.SH CONSIDERATIONS
7fe184
.sp
7fe184
Do not use \fBmongoimport\fP and \fBmongoexport\fP for
7fe184
full\-scale production backups because they may not reliably capture
7fe184
data type information. Use \fBmongodump\fP and
7fe184
\fBmongorestore\fP as described in http://docs.mongodb.org/manual/core/backups for this
7fe184
kind of functionality.
7fe184
.SH OPTIONS
7fe184
.sp
7fe184
Changed in version 3.0.0: \fBmongoexport\fP removed the \fB\-\-dbpath\fP as well as related
7fe184
\fB\-\-directoryperdb\fP and \fB\-\-journal\fP options. You must use
7fe184
\fBmongoexport\fP while connected to a \fBmongod\fP instance.
7fe184
7fe184
.sp
7fe184
Changed in version 3.0.0: \fBmongoexport\fP also removed support for writing data to
7fe184
\fBtsv\fP files with the \fB\-\-tsv\fP option.
7fe184
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B mongoexport
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B mongoexport
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-help
7fe184
Returns information on the options and use of \fBmongoexport\fP\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-verbose, \-v
7fe184
Increases the amount of internal reporting returned on standard output
7fe184
or in log files. Increase the verbosity with the \fB\-v\fP form by
7fe184
including the option multiple times, (e.g. \fB\-vvvvv\fP\&.)
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-quiet
7fe184
Runs the \fBmongoexport\fP in a quiet mode that attempts to limit the amount
7fe184
of output.
7fe184
.sp
7fe184
This option suppresses:
7fe184
.INDENT 7.0
7fe184
.IP \(bu 2
7fe184
output from \fIdatabase commands\fP
7fe184
.IP \(bu 2
7fe184
replication activity
7fe184
.IP \(bu 2
7fe184
connection accepted events
7fe184
.IP \(bu 2
7fe184
connection closed events
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-version
7fe184
Returns the \fBmongoexport\fP release number.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-host <hostname><:port>, \-h <hostname><:port>
7fe184
\fIDefault\fP: localhost:27017
7fe184
.sp
7fe184
Specifies a resolvable hostname for the \fBmongod\fP to which to
7fe184
connect. By default, the \fBmongoexport\fP attempts to connect to a MongoDB
7fe184
instance running on the localhost on port number \fB27017\fP\&.
7fe184
.sp
7fe184
To connect to a replica set, specify the
7fe184
\fBreplSetName\fP and a seed list of set members, as in
7fe184
the following:
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
<replSetName>/<hostname1><:port>,<hostname2><:port>,<...>
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
You can always connect directly to a single MongoDB instance by
7fe184
specifying the host and port number directly.
7fe184
.sp
7fe184
Changed in version 3.0.0: If you use IPv6 and use the \fB<address>:<port>\fP format, you must
7fe184
enclose the portion of an address and port combination in
7fe184
brackets (e.g. \fB[<address>]\fP).
7fe184
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-port <port>
7fe184
\fIDefault\fP: 27017
7fe184
.sp
7fe184
Specifies the TCP port on which the MongoDB instance listens for
7fe184
client connections.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-ipv6
7fe184
Enables IPv6 support and allows the \fBmongoexport\fP to connect to the
7fe184
MongoDB instance using an IPv6 network. All MongoDB programs and
7fe184
processes disable IPv6 support by default.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-ssl
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Enables connection to a \fBmongod\fP or \fBmongos\fP that has
7fe184
SSL support enabled.
7fe184
.sp
7fe184
The default distribution of MongoDB does not contain support for SSL.
7fe184
For more information on MongoDB and SSL, see http://docs.mongodb.org/manual/tutorial/configure\-ssl\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslCAFile <filename>
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Specifies the \fB\&.pem\fP file that contains the root certificate chain
7fe184
from the Certificate Authority. Specify the file name of the
7fe184
\fB\&.pem\fP file using relative or absolute paths.
7fe184
.sp
7fe184
The default distribution of MongoDB does not contain support for SSL.
7fe184
For more information on MongoDB and SSL, see http://docs.mongodb.org/manual/tutorial/configure\-ssl\&.
7fe184
.sp
7fe184
\fBWARNING:\fP
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
If the \fBmongo\fP shell or any other tool that connects to
7fe184
\fBmongos\fP or \fBmongod\fP is run without
7fe184
\fI\-\-sslCAFile\fP, it will not attempt to validate
7fe184
server certificates. This results in vulnerability to expired
7fe184
\fBmongod\fP and \fBmongos\fP certificates as well as to foreign
7fe184
processes posing as valid \fBmongod\fP or \fBmongos\fP
7fe184
instances. Ensure that you \fIalways\fP specify the CA file against which
7fe184
server certificates should be validated in cases where intrusion is a
7fe184
possibility.
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslPEMKeyFile <filename>
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Specifies the \fB\&.pem\fP file that contains both the SSL certificate
7fe184
and key. Specify the file name of the \fB\&.pem\fP file using relative
7fe184
or absolute paths.
7fe184
.sp
7fe184
This option is required when using the \fI\-\-ssl\fP option to connect
7fe184
to a \fBmongod\fP or \fBmongos\fP that has
7fe184
\fBCAFile\fP enabled \fIwithout\fP
7fe184
\fBallowConnectionsWithoutCertificates\fP\&.
7fe184
.sp
7fe184
The default distribution of MongoDB does not contain support for SSL.
7fe184
For more information on MongoDB and SSL, see http://docs.mongodb.org/manual/tutorial/configure\-ssl\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslPEMKeyPassword <value>
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Specifies the password to de\-crypt the certificate\-key file (i.e.
7fe184
\fI\-\-sslPEMKeyFile\fP). Use the \fI\-\-sslPEMKeyPassword\fP option only if the
7fe184
certificate\-key file is encrypted. In all cases, the \fBmongoexport\fP will
7fe184
redact the password from all logging and reporting output.
7fe184
.sp
7fe184
If the private key in the PEM file is encrypted and you do not specify
7fe184
the \fI\-\-sslPEMKeyPassword\fP option, the \fBmongoexport\fP will prompt for a passphrase. See
7fe184
\fIssl\-certificate\-password\fP\&.
7fe184
.sp
7fe184
The default distribution of MongoDB does not contain support for SSL.
7fe184
For more information on MongoDB and SSL, see http://docs.mongodb.org/manual/tutorial/configure\-ssl\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslCRLFile <filename>
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Specifies the \fB\&.pem\fP file that contains the Certificate Revocation
7fe184
List. Specify the file name of the \fB\&.pem\fP file using relative or
7fe184
absolute paths.
7fe184
.sp
7fe184
The default distribution of MongoDB does not contain support for SSL.
7fe184
For more information on MongoDB and SSL, see http://docs.mongodb.org/manual/tutorial/configure\-ssl\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslAllowInvalidCertificates
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Bypasses the validation checks for server certificates and allows
7fe184
the use of invalid certificates. When using the
7fe184
\fBallowInvalidCertificates\fP setting, MongoDB logs as a
7fe184
warning the use of the invalid certificate.
7fe184
.sp
7fe184
The default distribution of MongoDB does not contain support for SSL.
7fe184
For more information on MongoDB and SSL, see http://docs.mongodb.org/manual/tutorial/configure\-ssl\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslAllowInvalidHostnames
7fe184
New in version 3.0.
7fe184
7fe184
.sp
7fe184
Disables the validation of the hostnames in SSL certificates. Allows
7fe184
\fBmongoexport\fP to connect to MongoDB instances if the hostname their
7fe184
certificates do not match the specified hostname.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sslFIPSMode
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Directs the \fBmongoexport\fP to use the FIPS mode of the installed OpenSSL
7fe184
library. Your system must have a FIPS compliant OpenSSL library to use
7fe184
the \fI\-\-sslFIPSMode\fP option.
7fe184
.sp
7fe184
\fBNOTE:\fP
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
FIPS Compatible SSL is
7fe184
available only in \fI\%MongoDB Enterprise\fP\&. See
7fe184
http://docs.mongodb.org/manual/tutorial/configure\-fips for more information.
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-username <username>, \-u <username>
7fe184
Specifies a username with which to authenticate to a MongoDB database
7fe184
that uses authentication. Use in conjunction with the \fB\-\-password\fP and
7fe184
\fB\-\-authenticationDatabase\fP options.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-password <password>, \-p <password>
7fe184
Specifies a password with which to authenticate to a MongoDB database
7fe184
that uses authentication. Use in conjunction with the \fB\-\-username\fP and
7fe184
\fB\-\-authenticationDatabase\fP options.
7fe184
.sp
7fe184
If you do not specify an argument for \fI\-\-password\fP, \fBmongoexport\fP will
7fe184
prompt interactively for a password on the console.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-authenticationDatabase <dbname>
7fe184
If you do not specify an authentication database, \fBmongoexport\fP
7fe184
assumes that the database specified to export holds the user\(aqs credentials.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-authenticationMechanism <name>
7fe184
\fIDefault\fP: MONGODB\-CR
7fe184
.sp
7fe184
New in version 2.4.
7fe184
7fe184
.sp
7fe184
Changed in version 2.6: Added support for the \fBPLAIN\fP and \fBMONGODB\-X509\fP authentication
7fe184
mechanisms.
7fe184
7fe184
.sp
7fe184
Specifies the authentication mechanism the \fBmongoexport\fP instance uses to
7fe184
authenticate to the \fBmongod\fP or \fBmongos\fP\&.
7fe184
.TS
7fe184
center;
7fe184
|l|l|.
7fe184
_
7fe184
T{
7fe184
Value
7fe184
T}	T{
7fe184
Description
7fe184
T}
7fe184
_
7fe184
T{
7fe184
MONGODB\-CR
7fe184
T}	T{
7fe184
MongoDB challenge/response authentication.
7fe184
T}
7fe184
_
7fe184
T{
7fe184
MONGODB\-X509
7fe184
T}	T{
7fe184
MongoDB SSL certificate authentication.
7fe184
T}
7fe184
_
7fe184
T{
7fe184
PLAIN
7fe184
T}	T{
7fe184
External authentication using LDAP. You can also use \fBPLAIN\fP
7fe184
for authenticating in\-database users. \fBPLAIN\fP transmits
7fe184
passwords in plain text. This mechanism is available only in
7fe184
\fI\%MongoDB Enterprise\fP\&.
7fe184
T}
7fe184
_
7fe184
T{
7fe184
GSSAPI
7fe184
T}	T{
7fe184
External authentication using Kerberos. This mechanism is
7fe184
available only in \fI\%MongoDB Enterprise\fP\&.
7fe184
T}
7fe184
_
7fe184
.TE
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-gssapiServiceName
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Specify the name of the service using \fBGSSAPI/Kerberos\fP\&. Only required if the service does not use the
7fe184
default name of \fBmongodb\fP\&.
7fe184
.sp
7fe184
This option is available only in MongoDB Enterprise.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-gssapiHostName
7fe184
New in version 2.6.
7fe184
7fe184
.sp
7fe184
Specify the hostname of a service using \fBGSSAPI/Kerberos\fP\&. \fIOnly\fP required if the hostname of a machine does
7fe184
not match the hostname resolved by DNS.
7fe184
.sp
7fe184
This option is available only in MongoDB Enterprise.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-db <database>, \-d <database>
7fe184
Specifies the name of the database on which to run the \fBmongoexport\fP\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-collection <collection>, \-c <collection>
7fe184
Specifies the collection to export.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-fields <field1[,field2]>, \-f <field1[,field2]>
7fe184
Specifies a field or fields to \fIinclude\fP in the export. Use a comma
7fe184
separated list of fields to specify multiple fields.
7fe184
.sp
7fe184
For \fIcsv\fP output formats,
7fe184
\fBmongoexport\fP includes only the specified field(s), and the
7fe184
specified field(s) can be a field within a sub\-document.
7fe184
.sp
7fe184
For \fIJSON\fP output formats, \fBmongoexport\fP includes
7fe184
only the specified field(s) \fBand\fP the \fB_id\fP field, and if the
7fe184
specified field(s) is a field within a sub\-document, the
7fe184
\fBmongoexport\fP includes the sub\-document with all
7fe184
its fields, not just the specified field within the document.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-fieldFile <filename>
7fe184
An alternative to \fI\-\-fields\fP\&. The
7fe184
\fI\-\-fieldFile\fP option allows you to
7fe184
specify in a file the field or fields to \fIinclude\fP in the export and is
7fe184
\fBonly valid\fP with the \fI\-\-type\fP option
7fe184
with value \fBcsv\fP\&. The
7fe184
file must have only one field per line, and the line(s) must end with
7fe184
the LF character (\fB0x0A\fP).
7fe184
.sp
7fe184
\fBmongoexport\fP includes only the specified field(s). The
7fe184
specified field(s) can be a field within a sub\-document.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-query <JSON>, \-q <JSON>
7fe184
Provides a \fIJSON document\fP as a query that optionally limits
7fe184
the documents returned in the export. Specify JSON in \fBstrict
7fe184
format\fP\&.
7fe184
.sp
7fe184
For example, given a collection named \fBrecords\fP in the database
7fe184
\fBtest\fP with the following documents:
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
{ "_id" : ObjectId("51f0188846a64a1ed98fde7c"), "a" : 1 }
7fe184
{ "_id" : ObjectId("520e61b0c6646578e3661b59"), "a" : 1, "b" : 2 }
7fe184
{ "_id" : ObjectId("520e642bb7fa4ea22d6b1871"), "a" : 2, "b" : 3, "c" : 5 }
7fe184
{ "_id" : ObjectId("520e6431b7fa4ea22d6b1872"), "a" : 3, "b" : 3, "c" : 6 }
7fe184
{ "_id" : ObjectId("520e6445b7fa4ea22d6b1873"), "a" : 5, "b" : 6, "c" : 8 }
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
The following \fBmongoexport\fP uses the \fI\%\-q\fP option to
7fe184
export only the documents with the field \fBa\fP greater than or equal to
7fe184
(\fB$gte\fP) to \fB3\fP:
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
mongoexport \-d test \-c records \-q "{ a: { \e$gte: 3 } }" \-\-out exportdir/myRecords.json
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
The resulting file contains the following documents:
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
{ "_id" : { "$oid" : "520e6431b7fa4ea22d6b1872" }, "a" : 3, "b" : 3, "c" : 6 }
7fe184
{ "_id" : { "$oid" : "520e6445b7fa4ea22d6b1873" }, "a" : 5, "b" : 6, "c" : 8 }
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
You can sort the results with the \fI\%\-\-sort\fP option to
7fe184
\fBmongoexport\fP\&.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-type <string>
7fe184
\fIDefault\fP: json
7fe184
.sp
7fe184
New in version 3.0.0.
7fe184
7fe184
.sp
7fe184
Specifies the file type to export. The default format is \fIJSON\fP,
7fe184
bit it is possible to export \fIcsv\fP files.
7fe184
.sp
7fe184
If you specify \fBcsv\fP, then you must also use either
7fe184
the \fI\-\-fields\fP or the \fI\-\-fieldFile\fP option to
7fe184
declare the fields to export from the collection.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-out <file>, \-o <file>
7fe184
Specifies a file to write the export to. If you do not specify a file
7fe184
name, the \fBmongoexport\fP writes data to standard output
7fe184
(e.g. \fBstdout\fP).
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-jsonArray
7fe184
Modifies the output of \fBmongoexport\fP to write the
7fe184
entire contents of the export as a single \fIJSON\fP array. By
7fe184
default \fBmongoexport\fP writes data using one JSON document
7fe184
for every MongoDB document.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-pretty
7fe184
New in version 3.0.0.
7fe184
7fe184
.sp
7fe184
Outputs documents in a pretty\-printed format JSON.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-slaveOk, \-k
7fe184
Allows \fBmongoexport\fP to read data from secondary or slave
7fe184
nodes when using \fBmongoexport\fP with a replica set. This
7fe184
option is only available if connected to a \fBmongod\fP or
7fe184
\fBmongos\fP and is not available when used with the
7fe184
"\fImongoexport \-\-dbpath\fP" option.
7fe184
.sp
7fe184
This is the default behavior.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-forceTableScan
7fe184
New in version 2.2.
7fe184
7fe184
.sp
7fe184
Forces \fBmongoexport\fP to scan the data store directly:
7fe184
typically, \fBmongoexport\fP saves entries as they appear in the
7fe184
index of the \fB_id\fP field. Use \fI\%\-\-forceTableScan\fP to skip
7fe184
the index and scan the data directly. Typically there are two cases
7fe184
where this behavior is preferable to the default:
7fe184
.INDENT 7.0
7fe184
.IP 1. 3
7fe184
If you have key sizes over 800 bytes that would not be present
7fe184
in the \fB_id\fP index.
7fe184
.IP 2. 3
7fe184
Your database uses a custom \fB_id\fP field.
7fe184
.UNINDENT
7fe184
.sp
7fe184
When you run with \fI\%\-\-forceTableScan\fP, \fBmongoexport\fP
7fe184
does not use \fB$snapshot\fP\&. As a result, the export produced
7fe184
by \fBmongoexport\fP can reflect the state of the database at
7fe184
many different points in time.
7fe184
.sp
7fe184
\fBWARNING:\fP
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
Use \fI\%\-\-forceTableScan\fP with extreme caution
7fe184
and consideration.
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-skip <number>
7fe184
Use \fI\%\-\-skip\fP to control where \fBmongoexport\fP begins
7fe184
exporting documents. See \fBskip()\fP for information about
7fe184
the underlying operation.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-limit <number>
7fe184
Specifies a maximum number of documents to include in the
7fe184
export. See \fBlimit()\fP for information about
7fe184
the underlying operation.
7fe184
.UNINDENT
7fe184
.INDENT 0.0
7fe184
.TP
7fe184
.B \-\-sort <JSON>
7fe184
Specifies an ordering for exported results. If an index does
7fe184
\fBnot\fP exist that can support the sort operation, the results must
7fe184
be \fIless than\fP 32 megabytes.
7fe184
.sp
7fe184
Use \fI\%\-\-sort\fP conjunction with \fI\%\-\-skip\fP and
7fe184
\fI\%\-\-limit\fP to limit number of exported documents.
7fe184
.INDENT 7.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
mongoexport \-d test \-c records \-\-sort \(aq{a: 1}\(aq \-\-limit 100 \-\-out export.0.json
7fe184
mongoexport \-d test \-c records \-\-sort \(aq{a: 1}\(aq \-\-limit 100 \-\-skip 100 \-\-out export.1.json
7fe184
mongoexport \-d test \-c records \-\-sort \(aq{a: 1}\(aq \-\-limit 100 \-\-skip 200 \-\-out export.2.json
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
See \fBsort()\fP for information about the underlying
7fe184
operation.
7fe184
.UNINDENT
7fe184
.SH USE
7fe184
.SS Export in CSV Format
7fe184
.sp
7fe184
In the following example, \fBmongoexport\fP exports the
7fe184
collection \fBcontacts\fP from the \fBusers\fP database from the
7fe184
\fBmongod\fP instance running on the localhost port number
7fe184
\fB27017\fP\&. This command writes the export data in \fICSV\fP format
7fe184
into a file located at \fB/opt/backups/contacts.csv\fP\&.  The
7fe184
\fBfields.txt\fP file contains a line\-separated list of fields to
7fe184
export.
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
mongoexport \-\-db users \-\-collection contacts \-\-csv \-\-fieldFile fields.txt \-\-out /opt/backups/contacts.csv
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.SS Export in JSON Format
7fe184
.sp
7fe184
The next example creates an export of the collection \fBcontacts\fP
7fe184
from the MongoDB instance running on the localhost port number \fB27017\fP,
7fe184
with journaling explicitly enabled. This writes the export to the
7fe184
\fBcontacts.json\fP file in \fIJSON\fP format.
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
mongoexport \-\-db sales \-\-collection contacts \-\-out contacts.json \-\-journal
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.SS Export from Remote Host Running with Authentication
7fe184
.sp
7fe184
The following example exports the collection \fBcontacts\fP from the
7fe184
database \fBmarketing\fP . This data resides on the MongoDB instance
7fe184
located on the host \fBmongodb1.example.net\fP running on port \fB37017\fP,
7fe184
which requires the username \fBuser\fP and the password \fBpass\fP\&.
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
mongoexport \-\-host mongodb1.example.net \-\-port 37017 \-\-username user \-\-password pass \-\-collection contacts \-\-db marketing \-\-out mdb1\-examplenet.json
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.SH TYPE FIDELITY
7fe184
.sp
7fe184
\fBWARNING:\fP
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
\fBmongoimport\fP and \fBmongoexport\fP do not reliably
7fe184
preserve all rich \fIBSON\fP data types because \fIJSON\fP can
7fe184
only represent a subset of the types supported by BSON. As a result,
7fe184
data exported or imported with these tools may lose some measure of
7fe184
fidelity. See the \fBExtended JSON\fP
7fe184
reference for more information.
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
JSON can only represent a subset of the types supported by BSON. To
7fe184
preserve type information, \fBmongoexport\fP uses the \fBstrict
7fe184
mode representation\fP for certain
7fe184
types.
7fe184
.sp
7fe184
For example, the following insert operation in the \fBmongo\fP
7fe184
shell uses the \fBmongoShell mode representation\fP for the BSON types
7fe184
\fBdata_date\fP and \fBdata_numberlong\fP:
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
use test
7fe184
db.traffic.insert( { _id: 1, volume: NumberLong(2980000), date: new Date() } )
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
Use \fBmongoexport\fP to export the data:
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
mongoexport \-\-db test \-\-collection traffic \-\-out traffic.json
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
The exported data is in \fBstrict mode representation\fP to preserve type information:
7fe184
.INDENT 0.0
7fe184
.INDENT 3.5
7fe184
.sp
7fe184
.nf
7fe184
.ft C
7fe184
{ "_id" : 1, "volume" : { "$numberLong" : "2980000" }, "date" : { "$date" : "2014\-03\-13T13:47:42.483\-0400" } }
7fe184
.ft P
7fe184
.fi
7fe184
.UNINDENT
7fe184
.UNINDENT
7fe184
.sp
7fe184
See http://docs.mongodb.org/manual/reference/mongodb\-extended\-json for a complete list of
7fe184
these types and the representations used.
7fe184
.SH AUTHOR
7fe184
MongoDB Documentation Project
7fe184
.SH COPYRIGHT
7fe184
2011-2015
7fe184
.\" Generated by docutils manpage writer.
7fe184
.