- run gradle task buildForDocker
cd docker; docker-compose up
$ docker pull mongo:4.4.1
$ sudo apt-get install mongodb-clients
For running mongo inside host network (get access from mongo cli to running container)
$ docker run -d --name mon --network host mongo:4.4.1
$ docker stop mon
Remove container (if you need run mongo (name=mon) container with another arguments)
$ docker rm mon
$ mongo
-
Show All objects:
show dbs (collections, users, roles)
-
Select Database to Work With:
use databaseName
-
Show current db:
db
-
Create a Collection:
db.createCollection('collectionName')
-
Insert a Document in a Collection:
single doc
db.collectionName.insert({field1: 'val1'})
multiple docs
db.collectionName.insert([{field1: 'val1'}, {field2: 'val2'}])
-
Save or Update Document:
db.collectionName.save({'_id': new ObjectId('jhgsdjhgdsf'), field1: 'value', field2: 'value'})
-
Display Collection Records:
Retrieve all records
db.collectionName.find()
Retrieve limited number of records
db.collectionName.find().limit(10)
By id
db.collectionName.find({'_id': ObjectId('someId')})
Collection count
db.collectionName.count()
docker run -d --name mon --network host mongo:4.4.1
docker stop(start) mon
docker rm $(docker ps -a -q)
Docker compose helps to run set of services and could comfortably stop and delete unused containers with one command
docker-compose up
add --volumes if need remove volumes
docker-compose down (--volumes)
docker system df
Remove only dangling images, networks, containers
docker system prune
Remove dangling and unused images, networks, containers
docker system prune -a
Remove dangling and unused images, networks, containers and volumes
docker system prune -a --volumes