Blame SOURCES/mongoexport.1

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