Skip to main content

MongoDB | mongosh cli

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

Connection Configuration

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
title: "The Favourite",
genres: [ "Drama", "History" ],
runtime: 121,
rated: "R",
year: 2018,
directors: [ "Yorgos Lanthimos" ],
cast: [ "Olivia Colman", "Emma Stone", "Rachel Weisz" ],
type: "movie"
hoop exec mongo -- --eval 'db.movies.find()'
hoop exec mongo -i 'db.movies.find()'

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)'