Skip to main content

MongoDB | mongosh cli

Use the mongosh to execute one-off commands and open interactive sessions.

Connection Configuration

NameTypeDescription
MONGO_CONNECTION_URIenv-varMongoDB connection URI format

Connection Command

mongosh $MONGO_CONNECTION_URI --quiet

How to Use

Start an interactive session with mongosh client

hoop connect mongo

In the same connection, one-off process can be run as well

hoop exec mongo <<EOF
db.movies.insertOne(
{
title: "The Favourite",
genres: [ "Drama", "History" ],
runtime: 121,
rated: "R",
year: 2018,
directors: [ "Yorgos Lanthimos" ],
cast: [ "Olivia Colman", "Emma Stone", "Rachel Weisz" ],
type: "movie"
}
)
EOF
hoop exec mongo -- --eval 'db.movies.find()'
hoop exec mongo -i 'db.movies.find()'
WARNING

Be aware that the mongosh is also a node repl, the user could execute node scripts inside this connection. Example: hoop exec mongo -- --eval 'console.log(process.env)'