How do i export a mongodb database?
Docs Home → MongoDB Database Tools Show
Run
TipSee also:
NoteIf you are archiving stale data to save on storage costs, consider Online Archive in MongoDB Atlas. Online Archive automatically archives infrequently accessed data to fully-managed S3 buckets for cost-effective data tiering. Starting with MongoDB 4.4, For documentation on the MongoDB 4.2 or earlier versions of NoteThis documentation is for version
While
The ➤ Follow the Database Tools Installation Guide to install
The
Run
You must specify the
To connect to a local MongoDB instance running on port 27017, you do not have to specify the host or port. For example, to export the specified
To specify a host and/or port of the MongoDB instance, you can either:
For more information on the options available, see Options. To connect to a replica set to export its data, you can either:
By default,
For more information on the options available, see Options. To connect to a sharded cluster to export its data, you can either:
By default,
For more information on the options available, see Options. TipSee also:
Ensure that the connecting user possesses, at a minimum, the When
connecting to a If you need to preserve all rich
BSON data types when using
If
By default, If you specify read preference in the URI string and the WarningData Import and Export Conflicts With ($) and (.)Starting in MongoDB 5.0, document field names can be ( MongoDB Extended JSON v2 cannot differentiate between type wrappers and fields that happen to have the same name as type wrappers. Do not use Extended JSON formats in contexts where the corresponding BSON representations might include ( There are also restrictions on using --help Returns information on the options and use of --verbose, -v Increases the amount of internal reporting returned on standard output or in log files. Increase the verbosity with the --quiet Runs This option suppresses:
--version Returns the --config= New in version 100.3.0. Specifies the full path to a YAML configuration file containing sensitive values for the following options to
This is the recommended way to specify a password to The configuration file takes the following form:
Specifying
a password to the Be sure to secure this file with appropriate filesystem permissions. Note--uri= Specifies the resolvable URI connection string of the MongoDB deployment, enclosed in quotes:
Starting with
version
As a positional parameter, the connection string may be specified at any
point on the command line, as long as it begins with either
Only one connection string can be provided. Attempting to include more than one, whether using the For information on the components of the connection string, see the Connection String URI Format documentation. NoteSome components in the NoteWarningOn some systems, a password provided in a connection string with the
--host= Default: localhost:27017 Specifies the resolvable hostname of the MongoDB deployment. By default, To connect to a replica set, specify the
When specifying the replica set list format, You can also connect to any single member of the replica set by specifying the host and port of only that member:
If you use IPv6 and use the Alternatively, you can also specify the hostname directly in
the --port= Default: 27017 Specifies the TCP port on which the MongoDB instance listens for client connections. Alternatively, you can also specify the port directly in the
--ssl Enables connection to a Alternatively, you can also configure TLS/SSL support directly in the For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. --sslCAFile= Specifies the Alternatively, you can also specify the For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. --sslPEMKeyFile= Specifies the This option is required when using the Alternatively, you can also specify the For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. --sslPEMKeyPassword= Specifies the password to de-crypt the
certificate-key file (i.e. If the private key in the PEM file is encrypted and you do not specify the Alternatively, you can also specify the password directly in the For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. WarningOn some systems, a password provided directly using the --sslCRLFile= Specifies the For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. --sslAllowInvalidCertificates Bypasses the validation checks for server certificates and allows the use of invalid certificates. When using the WarningAlthough available, avoid using the Connecting to a Alternatively, you can also disable certificate validation directly in the
For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. --sslAllowInvalidHostnames Disables the validation of the hostnames in TLS/SSL certificates. Allows Alternatively, you can also disable hostname validation directly in the For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients. --username= Specifies a username with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the
Alternatively, you can also specify the username directly in the
If connecting to a
MongoDB Atlas cluster using the
See Connect to a MongoDB Atlas Cluster using AWS IAM Credentials for an example of each. --password= Specifies a password with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the
To prompt the user for the password, pass the
Alternatively, you can also specify the password directly in the If connecting to a
MongoDB Atlas cluster using the
See Connect to a MongoDB Atlas Cluster using AWS IAM Credentials for an example of each. WarningOn some systems, a password provided directly using the
--awsSessionToken= If connecting to a MongoDB Atlas cluster using the
See Connect to a MongoDB Atlas Cluster using AWS IAM Credentials for an example of each. Only valid when using the --authenticationDatabase= Specifies the authentication database where the specified If you do not specify an authentication database, If using the
GSSAPI (Kerberos), PLAIN (LDAP SASL), or Alternatively, you can also specify the authentication database directly in the
--authenticationMechanism= Default: SCRAM-SHA-1 Specifies the authentication mechanism the Changed in version 100.1.0: Starting in version
Alternatively, you can also specify the authentication mechanism directly in the --gssapiServiceName= Specify the name of the service using GSSAPI/Kerberos. Only required if the
service does not use the default name of This option is available only in MongoDB Enterprise. --gssapiHostName= Specify the hostname of a service using GSSAPI/Kerberos. Only required if the hostname of a machine does not match the hostname resolved by DNS. This option is available only in MongoDB Enterprise. --db= Specifies the name of the database on which to run the Alternatively, you can also specify the database directly in the
--collection= Specifies the collection to export. --fields= Specifies a field or fields to include in the export. Use a comma separated list of fields to specify multiple fields. If any of your field names include white space, use quotation marks to enclose the field list. For example, if you wished to
export two fields, For For
JSON output formats, See: Export Data in CSV Format using --fieldFile= An alternative to
See Use a File to Specify the Fields to Export in CSV Format for sample usage. --query= Provides a query as a JSON document (enclosed in quotes) to return matching documents in the export. You must enclose the query document in single quotes ( The query must be in Extended JSON v2 format (either relaxed or canonical/strict mode), including enclosing the field names and operators in quotes: For example, given a collection named
The following
The resulting file contains the following documents:
You can sort the results with the --type= Default: json Specifies the file type to export. Specify If you specify --out= Specifies a
file to write the export to. If you do not specify a file name, the --jsonFormat= Default: relaxed Modifies the output to use either canonical or relaxed mode of the MongoDB Extended JSON (v2) format. For differences between canonical and relaxed modes, see MongoDB Extended JSON (v2). --jsonArray Modifies the output of --pretty Outputs documents in a pretty-printed format JSON. --noHeaderLine By default, See Exclude Field Names from CSV Output for sample usage. --readPreference= Default: Specifies the
read preference for
If the read preference is also included in the WarningUsing
a read preference other than --skip= Use --limit= Specifies a maximum number of documents to include in the export. See --sort= Specifies an ordering for exported results. If an index does not exist that can support the sort operation, the results must be less than 32 megabytes. Use
See Run In the following example, The When you export in CSV format, you must specify the fields in the documents to export. The operation specifies the
The output would then resemble:
For CSV exports only, you can also specify the fields in a file containing the line-separated list of fields to export. The file must have only one field per line. For
example, you can specify the Then, using the
The
The CSV output would then resemble:
This
example creates an export of the
The following example exports the Specify the:
TipOmit the
Alternatively, you use the
TipOmit the password in the URI string to have
You can export only the results of a query by supplying a query filter with the
For instance, this command returns all documents in the
You must enclose the query document in single quotes ( New in version 100.1.0. To connect to a MongoDB Atlas cluster which has been configured to support authentication via AWS IAM credentials, provide a
Connecting to Atlas using AWS IAM credentials in this manner uses the If using an
AWS session token, as well, provide it with the
Note
If the AWS access key ID, secret access key, or session token include the following characters: those characters must be converted using percent encoding. Alternatively, the AWS access key ID, secret access key, and optionally session token can each be provided outside of the connection string using the
When provided as command line parameters, these three options do not require percent encoding. You may also set these credentials on your platform using standard AWS IAM environment variables.
If set, these credentials do not need to be specified in the connection string or via their explicit options. NoteIf you chose to use the AWS environment variables to specify these values, you cannot mix and match with the corresponding explicit or connection string options for these credentials. Either use the environment variables for access key ID and secret access key (and session token if used), or specify each of these using the explicit or connection string options instead. The following example sets these environment variables in the
Syntax for setting environment variables in other shells will be different. Consult the documentation for your platform for more information. You can verify that these environment variables have been set with the following command: Once set, the following example connects to a MongoDB Atlas cluster using these environment variables:
How do I export a MongoDB database to another server?So In Server 1, We need to take backup of our mongodb database using mongodump cmd & then create zip/tar file of dump folder & transfer the tar/zip file to server 2.. username of server 2.. ip address of server 2.. . pem file of server 2 (aws/google cloud provides you).. How do I export data from MongoDB to CSV?mongoexport command is used to export MongoDB Collection data to a CSV or JSON file. By default, the mongoexport command connects to mongod instance running on the localhost port number 27017. Field_name(s) - Name of the Field (or multiple fields separated by comma (,) ) to be exported.
How do I export a MongoDB database to JSON?Click on execute to export MongoDB data in JSON format using Studio3T.. Source: Make sure the source is entered correctly.. Format Option: Choose JSON-mongo shell/ JSON-mongoexport.. Target: Choose between clipboard/file & make sure the file path is defined.. How do I export data from robo3t?In the top right of the Robo 3T GUI there is a "View Results in text mode" button, click it and copy everything.. click the download button and now you have it in a spreadsheet.. |