Connect to mongodb shell from Docker
docker exec -it CONTAINER_ID/CONTAINER_NAME mongo
List docker DBs
show dbs
Use docker DB
use DB_NAME
List collections
show collections
Create docker container for mongo with authentication enabled
sudo docker run --name mongocontainer -d mongo --auth
Add admin user to Mongodb and create another user
use admin
db.createUser({ user: 'adminuser', pwd: 'abc123', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
db.auth("adminuser","abc123") use YOUR_DATABASE db.createUser({ user: 'someuser', pwd: 'abc123', roles: [ { role: "readWrite", db: "YOUR_DATABASE" } ] });
Delete all documents matching criteria
db.getCollection('message').deleteMany({messageStatus:"SCHEDULED"})