Skip to content

Instantly share code, notes, and snippets.

@KiranMantha
Last active March 19, 2024 07:22
Show Gist options
  • Select an option

  • Save KiranMantha/f1fc7475f93b966adc9f25f7278718d2 to your computer and use it in GitHub Desktop.

Select an option

Save KiranMantha/f1fc7475f93b966adc9f25f7278718d2 to your computer and use it in GitHub Desktop.
setup mongodb locally

Install mongodb

With homebrew

brew tap mongodb/brew
brew install mongodb-community
  • after installation, to start mongodb, run brew services start mongodb-community.
  • to check this: install mongodb vscode extension and add a connection with connection string: mongodb://localhost.
  • to stop mongodb, run brew services stop mongodb-community.

With docker

  • install docker and start it
  • run docker run --name mymongodb -d -p 27017:27017 mongo
  • this will pull the latest mongo image and run a container named mymongodb on external port 27017 and internal port 27017 in detached and published mode
  • to start using local mongodb, install mongodb vscode extension and add a connection with connection string: mongodb://localhost:27017.

Pro-tips

  • To backup database
mongodump --host=localhost --gzip --db <your-database-name> --archive=/<your-backup-folder-location>/<backup-file-name>.gz
  • To restore database from backup
mongorestore --gzip --archive=/<your-backup-folder-location>/<backup-file-name>.gz
  • To backup all databases
mongodump --out /<your-backup-folder-location>

Useful links

https://www.geeksforgeeks.org/how-to-back-up-and-restore-a-mongodb-database/

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