mongosh Command Examples

A new shell for MongoDB, replacement for mongo. Note: all connection options can be replaced with one string: mongodb://user@host:port/db_name?authSource=authdb_name. More information: https://www.mongodb.com/docs/mongodb-shell.

mongosh

mongosh --host {{host}} --port {{port}} {{db_name}}

mongosh --host {{host}} --port {{port}} --username {{username}} --authenticationDatabase {{authdb_name}} {{db_name}}

mongosh --eval '{{JSON.stringify(db.foo.findOne())}}' {{db_name}}