# Migrate from MongoDB® to SingleStore

To migrate your collection from MongoDB® to SingleStore, you can perform the following tasks:

* Replicate your MongoDB® collections using Change Data Capture (CDC).
* Back up your collections using `mongodump`, and then restore the backup into your SingleStore Helios workspace using `mongorestore`.
* Export your collection using `mongoexport`, and then import the exported data into your SingleStore Helios workspace using `mongoimport`.

## Replicate MongoDB® Collections to SingleStore

SingleStore allows you to perform a one-time data replication or ongoing CDC (Change Data Capture) from MongoDB® collections into SingleStore. Refer to [Replicate MongoDB® Collections to SingleStore](https://docs.singlestore.com/cloud/reference/singlestore-kai/replicate-mongodb-collections-to-singlestore.md) for more information.

## Use `mongodump` and `mongorestore`

## Back Up Data using `mongodump`

You can back up your collections in the BSON format using the `mongodump` command-line tool. Run the `mongodump` command from the system command-line. Refer to [mongodump](https://www.mongodb.com/docs/database-tools/mongodump/) for more information.

Here's a sample command to create a backup:

```shell
mongodump --uri="mongodb://<username>:<password>@<MongoDB_endpoint>:27017" \
--db=<database_name> --collection=<collection_name> \
--out=<path_to_output_directory>
```

For MongoDB® Atlas instances, use the `mongodb+srv://` scheme. For example:

```shell
mongodump --uri="mongodb+srv://<username>:<password>@<MongoDB_Atlas_endpoint>" \
--db=<database_name> --collection=<collection_name> \
--out=<path_to_output_directory>
```

## Restore the Backup using `mongorestore`

To restore the backup of your MongoDB® collections created using `mongodump` into your SingleStore Helios workspace, use the `mongorestore` command-line tool. Run the `mongorestore` command from the system command-line. Refer to [mongorestore](https://www.mongodb.com/docs/database-tools/mongorestore/) for more information.

> **📝 Note**: Do not restore and build the indexes specified in the backup. Use the `--noIndexRestore` option to ignore the indexes in the backup. To create indexes in SingleStore, use the [CREATE INDEX](https://docs.singlestore.com/cloud/reference/sql-reference/data-definition-language-ddl/create-index.md) command instead.

Here's a sample command to restore your MongoDB® backup into SingleStore:

```shell
mongorestore \
--uri 'mongodb://<user>:<password>@<SingleStore_Kai_endpoint>:27017/<target_database>?authMechanism=PLAIN&tls=true&loadBalanced=true' \
--noIndexRestore --ssl <path_to_backup>
```

## Use `mongoexport` and `mongoimport`

## Export Data using `mongoexport`

You can export your collection in either JSON or CSV format using the `mongoexport` command-line tool. Run the `mongoexport` command from the system command-line. Refer to [mongoexport](https://www.mongodb.com/docs/database-tools/mongoexport/) for more information.

Run the following command to export collections from a MongoDB® endpoint:

```shell
mongoexport --uri='mongodb://<user>:<password>@<MongoDB_endpoint>:27017' \
--db=<database_name> --collection=<collection_name> \
--out=<path_to_output/filename.[json|csv]>
```

Run the following command to export collections from a MongoDB® Atlas endpoint:

```shell
mongoexport --uri mongodb+srv://<username>@<atlas_endpoint>/<database_name> \
--collection=<collection_name> --out=<path_to_output/filename.[json|csv]>
```

## Import Data using `mongoimport`

To import the data exported using `mongoexport` into your SingleStore Helios workspace, use the `mongoimport` command-line tool. `mongoimport` supports Extended JSON, CSV, and TSV formats that have been exported via `mongoexport`. Run the `mongoimport` command from the system command-line. Refer to [mongoimport](https://www.mongodb.com/docs/database-tools/mongoimport/) for more information.

```shell
mongoimport \
--uri 'mongodb://<user>:<password>@<SingleStore_Kai_endpoint>:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true' \
--db <database_name> --collection <collection_name> \
--file <path_to_import_file/filename.[json|csv]>
```

If your file contains arrays, add `--jsonArray` after the database name.

***

Modified at: March 13, 2024

Source: [/cloud/reference/singlestore-kai/migrate-from-mongodb-to-singlestore/](https://docs.singlestore.com/cloud/reference/singlestore-kai/migrate-from-mongodb-to-singlestore/)

(An index of the documentation is available at /llms.txt)
