1. Using mongosh Interactive Shell
| Aspect | Detail |
| Default shell | 5.0+ (legacy mongo removed in 6.0) |
| Engine | Node.js based; full JS support |
2. Connecting with mongosh
mongosh "mongodb+srv://user:pwd@cluster.mongodb.net/app"
3. Using mongosh Helper Methods
| Helper | Detail |
| show dbs / show collections | List items |
| use db | Switch 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
| Feature | Detail |
| async/await | Top-level supported |
| Multi-line | Auto-detected (open braces) |
| History | ~/.mongoshrc.js for startup |
6. Configuring mongosh Settings
| Method | Detail |
| config.set(key, value) | Persistent setting |
| displayBatchSize | Default cursor batch in REPL |
| enableTelemetry | Opt-in / out |
7. Using mongosh Editor Mode
| Command | Detail |
| edit | Opens $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
| Aspect | Detail |
| Object members | db.<Tab>, db.coll.<Tab> |
| Field names | Schema-based completion in find/projection |
10. Exiting mongosh
| Method | Detail |
| exit / quit() | Clean exit |
| Ctrl+D | EOF exit |