Rock Mountain
  • Home
  • User Guide
    • Glass Web Components
    • Using reCAPTCHA
    • Publishing Source Code with Syntax Highlighting
  • Developer Guide
    • Getting Started
    • Adding NPM Packages
    • Database
      • Backing Up and Restoring Data
      • Database Schema
      • MongoDB Tips and Snippets
      • VS Code and the MongoDB Playground
    • Common Errors and Their Solutions
    • Developing Glass Web Components
    • DevOps
      • Build and Deployment Procedure
      • GitHub Conventions and Workflow
      • Merging Preview Into Main
    • File Structure
    • React Components
      • SiteLayout Component
      • Toggle Lazy Load Image Component
    • Update or Change the Fav Icon
    • References and Learning Resources
  • Icons
Powered by GitBook
On this page
  • mongodump
  • mongorestore
  • mongoexport
  • mongoimport
  1. Developer Guide
  2. Database

Backing Up and Restoring Data

PreviousDatabaseNextDatabase Schema

Last updated 3 years ago

Atlas backups are not available for M0 (Free Tier) clusters. You may use to back up your M0 cluster data and to restore that data. To learn how to manually back up your data, see .

Atlas provides instructions for connecting to an Atlas cluster using select MongoDB command line tools in the Command Line Tools tab.

  • Navigate to the Clusters page for your project.

  • Choose Command Line Tools for your desired cluster.

  • Download the CLI for Ubuntu/Debian and put the .deb file in your home directory.

  • Execute the following to install it: sudo dpkg -i mongocli_1.16.0_linux_x86_64.deb

  • Also install mongo-tools with sudo apt install mongo-tools

mongodump

mongodump | creates a binary export of the contents of a database

cd ~
mkdir mongdb-backups
cd mogodb-backups
mkdir 2021-06-12-303pm
mongodump --uri mongodb+srv://<mongodb_user>:<mongodb_password>@cluster0.cwrqa.mongodb.net/rm_production --forceTableScan -o /home/cburleson/mongodb-backups/2021-06-12-303pm
  • --forceTableScan is there because of an error, Unrecognized field 'snapshot'. Solution was to include this parameter. See: https://dba.stackexchange.com/questions/215534/mongodump-unrecognized-field-snapshot

  • -o is the target directory

mongorestore

The mongorestore program loads data from either a binary database dump created by mongodump or the standard input into a mongod or mongos instance.

Delete the preview database (it will be recreated automatically in the next step). Execute the following commands to recreate the preview database and restore each collection.

mongorestore --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/?authSource=admin" --db=rm_preview --collection=categories /home/cburleson/mongodb-backups/2021-06-12-303pm/rm_production/categories.bson
mongorestore --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/?authSource=admin" --db=rm_preview --collection=documents /home/cburleson/mongodb-backups/2021-06-12-303pm/rm_production/documents.bson
mongorestore --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/?authSource=admin" --db=rm_preview --collection=images /home/cburleson/mongodb-backups/2021-06-12-303pm/rm_production/images.bson

mongoexport

mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance.

mongoexport --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/rm_preview" --collection=documents --out=documents.json --forceTableScan --pretty

mongoimport

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.

mongoimport --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/rm_preview" --collection=documents --file=documents.json

See:

See:

mongodump
mongorestore
Command Line Tools
mongoexport
mongoimport