Blame SOURCES/mongoexport.1

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