MongoDB is a source-available cross-platform document-oriented database program for high-volume storage. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.
To import databases with the DigitalOcean Managed Databases MongoDB engine, you need:
A MongoDB client, like the mongo Shell or mongoimport
which is part of MongoDB Database Tools.
The database file stored locally on the same machine as your MongoDB client. If you are experimenting with MongoDB, you can download a sample database file from MongoDB’s official website. Otherwise, see how to export data from your database.
The database’s connection details. To get the database’s connection parameters from your control panel, visit the Databases page for your database. On the Overview tab, the Connection Details panel has your Connection string.
To import data to a MongoDB database, you can use mongoimport
to import specific collections data, or you can use mongorestore
to import a binary (BSON) full database backup. The exported database file must be stored locally on the same machine as your client.
mongoimport
The mongoimport
command imports content from a JSON, CSV, or TSV export to your database. It requires values for the following flags:
--uri
: The cluster’s connection string to the target database.--collection
: The name of the new collection you are creating.You can find the cluster’s connection string by referencing the connection details of your cluster.
The mongoimport
command uses the following syntax:
An example command looks like this:
A successful import returns:
Once you have imported the database file, you can verify it imported by connecting to the cluster and running the following command from the MongoDB shell:
The command returns a list of collection names.
mongorestore
The mongoimport
command imports content from a JSON, CSV, or TSV export to your database. It requires values for the following flags:
--uri
: The cluster’s connection string to the target database.You can find the cluster’s connection string by referencing the connection details of your cluster.
The mongoimport
command uses the following syntax:
An example command looks like this:
A successful import returns:
Once you have imported the database file, you can verify it imported by connecting to the cluster and running the following command from the MongoDB shell:
The command returns a list of collection names.
To export data from a MongoDB database, you can use mongoexport
to export specific collections data, or you can use mongodump
to export a binary (BSON) full database backup.
mongoexport
The mongoexport
command produces a JSON, CSV, or TSV export from your database. It requires values for the following flags:
--uri
: The cluster’s connection string to the target database.--collection
: The name of the new collection you are creating.--out
: The export’s file format (JSON, CSV, or TSV).You can find the cluster’s connection string by referencing the connection details of your cluster.
The mongoexport
command uses the following syntax:
An example command looks like this:
A successful export returns:
mongodump
The mongodump
command produces a binary (BSON) full backup of your database. It requires values for the following flags:
--uri
: The cluster’s connection string to the target database.--out
: The export’s file format (JSON, CSV, or TSV).You can find the cluster’s connection string by referencing the connection details of your cluster.
The mongodump
command uses the following syntax:
An example command looks like this:
A successful export returns:
To upload multiple databases simultaneously, see the mongodump
and mongorestore
commands. See MongoDB’s documentation to learn more about how to import your data or query your collections.