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
