> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help-legacy.galaxycloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# MongoDB - Simplify migration to Galaxy Database

Step-by-step guide for using a Docker image to migrate MongoDB databases to Galaxy Databases, including creating a new user post-migration for improved security and access control.

## Prerequisites
Before using this Docker image, make sure you have the following:

* Docker installed on your machine.
* Source and target MongoDB URIs ready and tested.
* IP whitelist configured on MongoDB Atlas if applicable.

|| This procedure should not be used for MongoDB Sharded Clusters.

### Step-by-Step Guide

#### Get the MongoDB URIs

1. Obtain the source MongoDB URI in the format: `mongodb+srv://<username>:<password>@<source-cluster>`
2. Get the MongoDB target URI from the Galaxy Database team in the format: `mongodb://<username>:<password>@<destination-host>:<port>`

![](https://storage.crisp.chat/users/helpdesk/website/273b1dc6f4f43800/image_1lbdhbe.png)

#### Run the Docker Container

Use the following command to run the migration container:

```
docker run --rm \
  -e SOURCE_URI="" \
  -e TARGET_URI="" \
  -e DB_NAME="example_source_db_name" \
  meteor/galaxy-mongodb-migrate:202506181938
```

Replace `SOURCE_URI`, `TARGET_URI`, and `DB_NAME` with your actual values.

#### Example

```
docker run --rm \
  -e SOURCE_URI="mongodb+srv://username:password@source-cluster.mongodb.net" \
  -e TARGET_URI="mongodb://username:password@destination-host-01.mongodb.net:27017,destination-host-02.mongodb.net:27017,destination-host-03.mongodb.net:27017/admin?replicaSet=replicaSetName" \
  -e DB_NAME="example_source_db_name" \
  meteor/galaxy-mongodb-migrate:202506181938
```

## SSL Configuration for Target Database

**Important SSL Considerations:**

If your target database has SSL enabled, follow these guidelines:

1. **Always include** `authSource=admin` in your connection string
2. **Omit** the `ssl=true` parameter from the connection string
3. If `ssl=true` is required, you must download the SSL certificate from the Galaxy Database dashboard and provide it through the appropriate parameter

#### SSL Connection Examples

**Recommended approach (without ssl=true parameter):**
```
docker run --rm \
  -e SOURCE_URI="mongodb+srv://username:password@source-cluster.mongodb.net" \
  -e TARGET_URI="mongodb://username:password@destination-host-01.mongodb.net:27017,destination-host-02.mongodb.net:27017,destination-host-03.mongodb.net:27017/admin?authSource=admin&replicaSet=replicaSetName" \
  -e DB_NAME="example_source_db_name" \
  meteor/galaxy-mongodb-migrate:202506181938
```

**If SSL certificate is required:**
```
docker run --rm \
  -v /path/to/ssl-cert.pem:/ssl-cert.pem \
  -e SOURCE_URI="mongodb+srv://username:password@source-cluster.mongodb.net" \
  -e TARGET_URI="mongodb://username:password@destination-host-01.mongodb.net:27017,destination-host-02.mongodb.net:27017,destination-host-03.mongodb.net:27017/admin?authSource=admin&ssl=true&sslCAFile=/ssl-cert.pem&replicaSet=replicaSetName" \
  -e DB_NAME="example_source_db_name" \
  meteor/galaxy-mongodb-migrate:202506181938
```

**Note:** Download the SSL certificate from your Galaxy Database dashboard before using the second approach.

## Creating User for the Database

We recommend creating a new user specifically for the database after migration to enhance security and access control.

#### Recommended Steps

 
1. Database Migration: Execute the database migration ensuring all data is successfully transferred to the new environment.

2. Connect to the Destination Database: Use our compass guide on connecting to MongoDB.
 
3. Select the Database: Select the migrated database (e.g., use example_db_name).
 
4. Create the New User: Create a new user specific to this database. For example:

```
db.createUser({
  user: "newuser",
  pwd: "<new-secure-password>",
  roles: ["readWrite"]
})
```

Replace `<new-secure-password>` with the password for the new user.

 
5. Verify the New User: Ensure the new user has been successfully created:

```
db.getUsers()
```

Now you can use a URI like this in your Meteor app:

`mongodb://newuser:pass@destination-host-01.mongodb.net:27017,destination-host-02.mongodb.net:27017,destination-host-03.mongodb.net:27017/example_db_name?replicaSet=NameOfYourReplicaSet&readPreference=secondary`

## Security Considerations

* Use secure passwords for your users.
* Assign only necessary permissions.
* Regularly review user privileges.

## Troubleshooting

* Check connection details and permissions.
* Review logs for errors.

## Users

To effectively manage your MongoDB cluster, the Galaxy Database team sets up several MongoDB users within your clusters:

* admin@admin: Initial user with administrative privileges.
* galaxyadmin@admin: Technical user required for automation.
* galaxybackup@admin: User designated for performing backups.
* galaxymonitor@admin: User used for monitoring.

**Please do not delete these users**.

## Creating a MongoDB user for Oplog

To set up an oplog user, configure a MongoDB replica set:

1. Connect to your database using our compass guide.

2. Open your console and run:

```
db.createUser({
  user: "oplogger",
  pwd: "PasswordForOplogger",
  roles: [{ role: "read", db: "local" }]
})
```

The oplog user must be created in the admin database with read permissions to the local database.

3. Your new MongoDB connection string will be:

`mongodb://oplogger:PasswordForOplogger@mongo-1.example.com,mongo-2.example.com,mongo-3.example.com/local?authSource=admin&replicaSet=replicaSetName`

Ensure `authSource=admin` is included at the end.

## Support

For migrations without downtime, contact our team at *support@meteor.com.*

This documentation provides a comprehensive guide for using Docker to migrate MongoDB databases to Galaxy Databases, along with best practices for creating and managing users post-migration.