How to dump and restore my MongoDB database on Scalingo

There are two ways to dump a distant database and restore the data in your Scalingo database. The first one involves dumping the data on your local workstation and the second one involves doing the same operations from within a Scalingo one-off container (see application tasks).

Dump and Restore from your local workstation

To dump and restore database from your local workstation, you will need the MongoDB CLI tools. Installation procedures can be found here. You will also need a way to access your database.

A MongoDB URL is usually formatted like:


To get the URL of your database, go to the ‘Environment’ part of your dashboard or run the following command:

$ scalingo --app my-app env | grep MONGO

If your remote database URL is:


Setup the tunnel

$ scalingo --app my-app db-tunnel SCALINGO_MONGO_URL

Building tunnel to
You can access your database on ''


The command definition is:

$ mongodump --username <username> --password <password> --host <host>:<port> --db <db>

Applied to our example:

$ mongodump --username my-db --password pass --host --db my-db

The command will create a dump directory in your current working directory.

As you can see we use the host and port provided by the tunnel, not those of the URL.


The command definition is:

$ mongorestore --username <username> --password <password> --host <host>:<port> --db <db> <dump directory>

With our example:

$ mongorestore --username my-db --password pass --host --db my-db dump/my-db

In addition you may use the --drop option to delete the existing data in the database.

Dump and Restore from Scalingo one-off container

You can dump and restore your database remotely using the command-line-tool and a one-off container (see application tasks). The advantage of this method is the network. From your workstation you don’t always have a good bandwidth. From our infrastructure, data transfers will be way faster.


$ scalingo --app my-app run bash

[00:00] Scalingo ~ $ mongodump --username user --password pass --host --db my-db

# Do something with the dump, i.e send it with FTP or to an external server


$ scalingo --app my-app run bash

# Get a dump from a remote place, with 'curl' or 'ftp'

[00:00] Scalingo ~ $ mongorestore --uri $SCALINGO_MONGO_URL --db my-db dump/my-db

After exiting the one-off container, the dump will be lost, you’ve to do something with it in the container.

mode_edit Suggest edits