Skip to content

Instantly share code, notes, and snippets.

@echo-dave
Last active November 25, 2020 01:46
Show Gist options
  • Save echo-dave/3b590ad493215c8d7ca543a8b9989e62 to your computer and use it in GitHub Desktop.
Save echo-dave/3b590ad493215c8d7ca543a8b9989e62 to your computer and use it in GitHub Desktop.
Migrate MongoDB to MongoDB Atlas

Note some of this is from memory months ago in combination with old nots so let me know if updating is needed.

Backup and Restore

::mongodump:: to backup and maintain all the BSON although not recomended for sharded clusters - see atlas documentation.

mongodump —-uri “mongodb://heroku_xxxxx:PASSWORD@ds261238.mlab.com:61238/heroku_00xzkv83” 

note that for mlab the username and the authentication database are the same

::mongorestore:: to restore  initial database using a mongodump directory:

mongorestore -—uri=“mongodb+srv://USERNAME:PASSWORD@cluster0-5yogy.mongodb.net/test?authSource=admin” —-db=DBNAME DBDUMP-LOCAL-PATH 

uri connection string of username:password@server  followed by database to restore into 

—-db=database 

and then the dump directory / database dumb

Be sure that you have already set up you whitelist ips for the cluster. If on standard Heroku without special addons you'll need to use 0.0.0.0 which means anyone can try to connect to it.

Add database from the Clusters  menu item on right after logging into Atlas Setup users and ip whitelist under CONNECT Setup database and collections under COLLECTIONS

Mongo Compass

I recomend using Mongo's Compass application to ensure that the database setup and reachable before updating the connection string in your app. This just ensures you arent tying to fix things that arent broken inside you spp if there's an issue. Compass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment