Using MongoDB Shell Tools

1. Using mongosh Interactive Shell

AspectDetail
Default shell5.0+ (legacy mongo removed in 6.0)
EngineNode.js based; full JS support

2. Connecting with mongosh

mongosh "mongodb+srv://user:pwd@cluster.mongodb.net/app"

3. Using mongosh Helper Methods

HelperDetail
show dbs / show collectionsList items
use dbSwitch database
db.help() / db.coll.help()Inline help

4. Running Scripts with mongosh

mongosh "$URI" --file maintenance.js
mongosh --eval 'db.getSiblingDB("app").orders.countDocuments()'

5. Using mongosh REPL Features

FeatureDetail
async/awaitTop-level supported
Multi-lineAuto-detected (open braces)
History~/.mongoshrc.js for startup

6. Configuring mongosh Settings

MethodDetail
config.set(key, value)Persistent setting
displayBatchSizeDefault cursor batch in REPL
enableTelemetryOpt-in / out

7. Using mongosh Editor Mode

CommandDetail
editOpens $EDITOR for current line
config.set("editor","vim")Choose editor

8. Accessing MongoDB Logs in mongosh

db.adminCommand({ getLog: "global" });

9. Using Tab Completion in mongosh

AspectDetail
Object membersdb.<Tab>, db.coll.<Tab>
Field namesSchema-based completion in find/projection

10. Exiting mongosh

MethodDetail
exit / quit()Clean exit
Ctrl+DEOF exit