Mongosh docker

Using docker exec to run commands on a mongodb container

Published on · 1 min read · 1 view · 1 reading right now

DOCKER
MONGODB

Connect

docker exec -it <container_name> mongosh -u <user_name> -p <password>

With -u an -p options being optional(obv).

Commands

show databases

use <database_name>

db.<collection_name>.find() # get all data in the collection
db.<collection_name>.insertOne({ ... }) # insert data in the collection

exit
0 likes

Other articles