Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Mongo/Docker Cheatsheet
- To download the latest image:
- `$ docker pull mongo:latest`
- To run a mongo container with detached mode(`-p`) and with ports mapped (`-p 27017-27017:27017-27019`) and named (`--name mongodb`):
- `$ docker run -d -p 27017-27017:27017-27019 --name mongodb mongo:latest`
- To list the docker images:
- `$ docker images`
- To stop a container:
- `$ docker stop mongodb`
- To remove a container:
- `$ docker rm mongodb`
- To list running containers:
- `$ docker ps -a `
- To enter an interactive terminal(`-it mongodb bash`):
- `$ docker exec -it mongodb bash`
- To login as a mongo client, enter a interactive terminal, then type:
- `$ mongo`
- To show the databases:
- `> show dbs`
- To switch to a database:
- `> use <database>`
- To save a record to the database:
- `> db.people.save({firstname: "sean", lastname: "dittmar" })`
- To show all records:
- `> db.people.find({})`
- To find a record using criteria:
- `> db.people.find({firstname: "Sean"})`
- To exit mongo:
- `> quit`
- To exit docker container:
- `$ exit`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement