The MongoDB Shell, mongosh, is a fully functional JavaScript and Node.js 16.x REPL environment for interacting with MongoDB deployments. You can use the MongoDB Shell to test queries and operations directly with your database.
# To connect to a local database on the default port ('mongodb://localhost:27017'):
mongosh
# To connect to a database:
mongosh --host <host> --port <port> <db_name>
# To authenticate using the specified username on the specified database (you will be prompted for a password):
mongosh --host <host> --port <port> --username <username> --authenticationDatabase <authdb_name> <db_name>
# To evaluate a JavaScript expression on a database:
mongosh --eval '<JSON.stringify(db.foo.findOne())>' <db_name>