liveBook · Manning

Mongorestore

As explained in MongoDB 8.0 in Action, Third Edition

mongorestore is a MongoDB Database Tools utility that restores data from BSON dump archives into a MongoDB database.

mongorestore is a MongoDB Database Tools utility that loads data from a Binary JSON (BSON) dump into a MongoDB database. It is useful for loading sample data into a local Atlas cluster and for restoring a logical backup when Atlas Cloud Backup is unavailable, as on M0 free clusters. section 13.3.2 section 21.1.1

To load the supplied sample data into a local Atlas cluster:

  • 1. Install MongoDB Database Tools, then download the sample archive with `curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive`. section 13.3.2
  • 2. Get the cluster’s connection string with `atlas deployments connect --connectWith connectionString <name>`, replacing `<name>` with your local cluster’s name. section 13.3.2
  • 3. Pass the archive and connection string to mongorestore. After it finishes, reconnect with `atlas deployments connect --type LOCAL` and run `show dbs` to check for the sample databases. section 13.3.2
mongorestore --archive=sampledata.archive \
--uri mongodb://localhost:32769/?directConnection=true

This command loads `sampledata.archive` into the local cluster identified by the URI. Replace the example URI with your cluster’s connection string. section 13.3.2

For an M0 backup workflow, mongodump creates the logical BSON dump and mongorestore restores it. This is an alternative to managed snapshots, not an equivalent point-in-time recovery method. Exporting and importing a large database can take substantial time and processing power. section 21.1.1 section 21.1.2

In Atlas, mongorestore does not support `--restoreDbUsersAndRoles`, `--oplogReplay`, or `--preserveUUID`. Re-create users and roles separately if needed; oplog replay cannot recover changes since the last backup, and restored collections receive new UUIDs. section 21.1.2

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Walks through an archive restore and verification, then identifies Atlas-specific option limits; does not develop a full backup procedure.
Examples
Uses a downloaded sample archive, a local-cluster connection string, a mongorestore command, and a database-listing check.
What it assumes
Introduces BSON dump restoration while requiring MongoDB Database Tools, a downloaded archive, and the target cluster’s connection string.
What you can do after
Operate/configure it to load a BSON archive into a local Atlas cluster and verify that databases appear.
How it connects
Connects mongorestore to mongodump, BSON logical backups, Atlas CLI local deployments, and Atlas Cloud Backup.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.