---
title: Back up and restore MongoDB® Databases with MongoDB® tools
description: This page shows you how to back up and restore MongoDB® Databases with MongoDB® command line tools
tags: databases mongodb document backup database-nodes
---
import Requirements from '@macros/iam/requirements.mdx'


Managed MongoDB® provides fully-managed MongoDB® Instances. This tutorial shows how to backup and restore your MongoDB® Databases with the MongoDB® `mongodump` and `mongorestore` command line database tools.

<Requirements />

  - A Scaleway account logged into the [console](https://console.scaleway.com)
  - A [MongoDB® Database Instance](/managed-mongodb-databases/how-to/create-a-database-instance/)
  - Installed a [MongoDB®-compatible client](https://www.mongodb.com/try/download/shell)
  - Installed [mongodump and mongorestore tools](https://www.mongodb.com/docs/database-tools/installation/installation/)


<Message type="important">
  This tutorial shows you basic restore and backup operations. If you need additional options for the operations, refer to the [official MongoDB® documentation](https://www.mongodb.com/docs/manual/tutorial/backup-and-restore-tools/).

  Make sure you keep the `--ssl` and `--sslCAFile=<file.pem>` options in your commands, as you will need to authenticate using the default SSL certificate when you connect to your Database Instance.
</Message>

## How to back up a MongoDB® Database Instance

To create backups, we will use the `mongodump` tool, which can create backups for an entire Database Instance, logical database or collection. It can also use a query to back up part of a collection.

1. Navigate to the [Scaleway console](https://console.scaleway.com/).
2. Click **MongoDB® Databases** under **Databases** on the side menu. A list of your Database Instances displays.
3. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
4. Download the Database Instance's SSL certificate.
    <Message type="important">
      Make sure you know the path to the certificate on your local machine, as it will be used in a later step.
    </Message>
5. Run the following command, replacing the values according to the table below.
    ```
    mongodump \
      --host=<ip-address> \
      --port=<port> \
      --username=<username> \
      --password="<password>" \
      --out=/path/to/backup \
      --ssl \
      --sslCAFile=<file.pem> \
      --authenticationMechanism=PLAIN
    ```

    `host`
    : the IP address of your Database Instance

    `port`
    : the connection port of your Database Instance

    `username`
    : the username of the database user created upon Database Instance creation

    `password`
    : the password of the database user created upon Database Instance creation

    `out`
    : the path to the folder where you want the backups to be stored on your machine

    `sslCAFile`
    : the path to where your SSL certificate is stored

    `authenticationMechanism`
    : the list of authentication mechanisms the server accepts

    If no response is returned, the operation was successful. You can make sure the backup occurred by checking that new files were added to the destination folder.

## How to restore from a backup

You can restore either an entire database backup or a subset of a backup using `mongorestore`.

The tool restores binary backups created using `mongodump`.

You can restore the backed up data to any database within any Database Instance.

Run the following command, replacing the values according to the table above. You must specify the name of the destination `db`.
```
mongorestore \
  --host=<ip-address> \
  --port=<port> \
  --username=<username> \
  --password=<password> \
  /path/to/backup \
  --db=rdb \
  --ssl \
  --sslCAFile=<file.pem> \
  --authenticationMechanism=PLAIN
```
`db`
: the name of the database to which you want to restore the backup

If the procedure was successful, you will see an output like the following:

```
2023-09-04T17:50:29.893+0200	1 document(s) restored successfully. 0 document(s) failed to restore.
```
