Skip to main content

MongoDB Shell (mongosh)

Introduced in June 2020 (blog post), available as a standalone package, mongosh provides a fully functional JavaScript/Node.js environment for interacting with MongoDB deployments.

🌐 mongodb.com/products/tools/shell, code docs

Getting started

mongosh <connection_string>

Migrating from Legacy mongo Shell: Compatibility Changes with Legacy mongo Shell

Commands

CommandAction
dbDisplay the database currently used
use <database>Switch database
db.myCollection.insertOne({ x: 1 })Create an entry in a collection
db.myCollection.find()Find all entries in a collection