-
run below commands:
brew tap mongodb/brewbrew 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.
- install docker and start it
- run
docker run --name mymongodb -d -p 27017:27017 mongo - this will pull the latest
mongoimage and run a container namedmymongodbon 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.
- 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>https://www.geeksforgeeks.org/how-to-back-up-and-restore-a-mongodb-database/