Chase AdamsChase Adams
AboutContentPromptsPlayground

How to Restore a MongoDB Database from Compass

Essays and updates on product, engineering, and AI by Chase Adams.

1 minute read

I often find that I want to restore a MongoDB database locally from MongoDB (Preview database) Atlas to determine if I've made any breaking changes.

Restoring your MongoDB database

  1. Download a backup from MongoDB Atlas.
  2. Unzip the backup. In this case, I unzipped it to my Downloads directory as dump.
  3. run a Docker container with the following flags:
    • -p <TO>:<FROM> - To is the port that you are serving on your local machine and From is the container's process port for Mongo (unless specified otherwise, it's 27017)
    • -v <LOCAL DB DIRECTORY>:<DOCKER DB PATH> - Local DB Directory is where I unzipped the backup. Docker DB Path is the directory Mongo will use to serve a database. Unless specified otherwise, this is /data/db
      docker container run -p 27018:27017 -v $HOME/Downloads/dump:/data/db mongo:5.0.7
      

Accessing your MongoDB database

Now from Mongo Compass you should be able to connect to your locally running Mongo instance with this connection string:

mongodb://@localhost:27018?authSource=admin&readPreference=primary&directConnection=true&ssl=false

Notice the 27018? In this case, because that's the port I designated for Mongo to serve from on my computer, this is the port I want to connect to.

First Cohort
No Coding Experience Required

Build Your Website with AI—No Code Required

Learn to create and deploy professional websites using ChatGPT and Claude. Go from complete beginner to confident website builder.

Start Building Today

Post Details

Published
Nov 27, 2022
Category
Engineering
Share
Ask ChatGPT
Ask Claude

Latest Posts

Joining Rocket Money as VP of AI Engineering

Joining Rocket Money as VP of AI Engineering

Leading AI engineering at Rocket Money to write the playbook for how engineering teams operate in the AI era

AboutAI Workflow SpecContentStacksNewsletterPromptsRSS

Ask me anything

Loading...

Hi! Ask me anything about Chase's work.

I can answer questions based on his blog posts and articles.

Experimental: This chat is a side project I work on in my free time. Responses may vary in quality and accuracy.