Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for migrating to MongoDB from FerretDB #3374

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions website/docs/migration/_category_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
label: Migrating to FerretDB
position: 9
link:
type: generated-index
description: >
This section details the procedures on how to migrate to FerretDB
66 changes: 66 additions & 0 deletions website/docs/migration/migrating-to-ferretdb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
sidebar_position: 2
---

# Migrate from MongoDB to FerretDB
AlekSi marked this conversation as resolved.
Show resolved Hide resolved

Before you begin this section of the migration process, go through the pre-migration process so as to ensure a successful migration from MongoDB to FerretDB:

- [Pre-migration testing](premigration-testing.md)

This guide will help you migrate your data from MongoDB – locally or online – to FerretDB.

As an open-source MongoDB alternative, FerretDB is built to work with many MongoDB tools.
In that case, you can migrate your data using MongoDB native tools such as `mongodump`/`mongorestore` and `mongoexport`/`mongoimport`.

Before you go forward with the migration, you need to have the following:

- MongoDB connection URI
- FerretDB connection URI
- MongoDB native tools

## Backup your MongoDB data

To backup your MongoDB instance using `mongodump` or `mongoexport`, you'll need to set the connection string to your MongoDB instance (e.g. `"mongodb://127.0.0.1:27017"`) to run the following command:

```sh
mongodump --uri="mongodb://<yourusername>:<yourpassword>@<host>:<port>"
```

The `mongodump` command will create a dump of all the data in the instance, consisting of BSON files of all the collections.
Also, you can migrate a specific database (e.g. `--db=test`) or collection (e.g. `--collection=supply`) using their respective parameters after the `--uri` connection string.

:::caution
If you include the database in your connection string, there's no need to specify a database name for the backup or restore process.
:::

```sh
mongoexport --uri="mongodb://<yourusername>:<yourpassword>@<host>:<port>" --db=<database-name> --collection=<collection-name> --out=<collection>.json
```

On the other hand, `mongoexport` does not provide a direct way to export all the collections at once, like `mongodump` does.

Instead, you need to set the connection string to connect with your preferred database and then run the command together with the parameters for the collection (`--collection=myCollection`) and the directory you want to export to (e.g. `--out=collection-name.json`).

## Restore your data to FerretDB

To restore or import your backed-up data to FerretDB, set the connection string to your FerretDB instance and use `mongorestore` and `mongoimport`.

Run the following command in your terminal, from your `dump` folder:

```sh
mongorestore --uri="mongodb://<yourusername>:<yourpassword>@<host>:<port>/?authMechanism=PLAIN"
```

With this command, you can restore all the data in `dump` into your FerretDB instance.
You can also specify the database and collection (`dump/<database>/<collection>`) you want to restore from the `dump` folder, according to your preferences.

To import your database using `mongoimport`, run the command from the terminal directory where you exported your data:

````sh

```sh
mongoimport--uri="mongodb://<yourusername>:<yourpassword>@<host>:<port>/?authMechanism=PLAIN" --db=<database-name> --collection=<collection-name> --file=<collection>.json
````

The command will import the specified collection you exported from your MongoDB instance to FerretDB.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
sidebar_position: 9
sidebar_position: 1
---

# Migrating from MongoDB to FerretDB
# Pre-migration testing

To ensure a smooth and successful migration from MongoDB, we offer several methods through which you can test your application with FerretDB.

## Operation modes

We offer multiple operation modes which help facilitate the testing of your application by enabling FerretDB to act as a proxy.
For more details, refer to the [operation modes](configuration/operation-modes.md).
For more details, refer to the [operation modes](../configuration/operation-modes.md).

### Manual and automated testing with `diff-normal` mode

For details on how to install FerretDB, refer to the [quickstart guide](../quickstart-guide/).
For details on how to install FerretDB, refer to the [quickstart guide](../../quickstart-guide/).

You can manually test your application or use integration tests, among other methods.
Afterward, you can inspect the differential output for errors or inconsistencies between responses that require your attention.
Expand All @@ -22,7 +22,7 @@ As an example, let us say that your application performs some complex query and
You would do the following:

1. Start FerretDB in `diff-normal` mode.
This can be achieved by using the `--mode` [flag](configuration/flags.md) or by setting the `FERRETDB_MODE` environment variable.
This can be achieved by using the `--mode` [flag](../configuration/flags.md) or by setting the `FERRETDB_MODE` environment variable.
2. Run `mongosh` and insert some documents.
3. Run a query to fetch the first post from each author sorted by date and author.

Expand Down Expand Up @@ -83,7 +83,7 @@ You would do the following:
Continuing with the same example above, we can further examine the diff output while in `diff-proxy` mode.

1. Run FerretDB in `diff-proxy` mode.
This can again be achieved by using the `--mode` [flag](configuration/flags.md) or by setting the `FERRETDB_MODE` environment variable as already shown.
This can again be achieved by using the `--mode` [flag](../configuration/flags.md) or by setting the `FERRETDB_MODE` environment variable as already shown.
2. Re-run the query.

```js
Expand Down