A high-performance MongoDB shell written in Rust that bridges SQL and MongoDB - query your MongoDB databases using familiar SQL syntax or native MongoDB commands.
Note: This is an independent community project, not affiliated with MongoDB Inc.
- 🔄 SQL to MongoDB - Write SQL queries, execute as MongoDB commands automatically
- ⚡ Blazing Fast - Native Rust implementation with async I/O
- 🎨 Beautiful Output - Syntax highlighting, formatted tables, and pretty JSON
- 🧠 Smart Completion - Context-aware auto-completion for collections, fields, and commands
- 💾 Named Queries - Save and reuse complex queries with parameters
- 📊 Rich SQL Features - Array indexing, date functions, arithmetic operations, and more
- 🤖 MCP Server - Let AI assistants query MongoDB with 15 built-in tools
cargo install mongosh# Connect to MongoDB
mongosh mongodb://localhost:27017
# Use SQL syntax
SELECT name, email FROM users WHERE age > 18 ORDER BY name LIMIT 10
# Or native MongoDB syntax
db.users.find({ age: { $gt: 18 } }).sort({ name: 1 }).limit(10)
# Save frequently used queries
query save active_users db.users.find({status: 'active'})
query active_usersQuery MongoDB using standard SQL syntax - automatically translated to MongoDB queries:
-- Basic queries
SELECT * FROM orders WHERE status = 'completed'
-- Aggregations
SELECT category, COUNT(*) as total, AVG(price) as avg_price
FROM products
GROUP BY category
HAVING total > 10
-- Array access
SELECT tags[0] AS primary_tag FROM posts WHERE tags[-1] = 'featured'
-- Date filtering
SELECT * FROM events WHERE created_at > DATE '2024-01-01'
-- Arithmetic operations
SELECT price * quantity * 1.13 AS total FROM orders
-- Query analysis
EXPLAIN SELECT * FROM users WHERE age > 18Save and reuse queries with parameter substitution:
// Save a parameterized query
query save user_by_email db.users.findOne({email: '$1'})
// Execute with parameters
query user_by_email john@example.com
// List all saved queries
query listAuto-complete datasource names from your configuration:
# Tab completion for datasources
mongosh -d prod<TAB> # Completes to: mongosh -d production
# Works with options too
mongosh --datasource dev<TAB># Pretty JSON (default)
db.users.find().limit(1)
# Compact JSON
mongosh --format json-compact
# Table format
mongosh --format table
# Shell-style output
mongosh --format shellEnable AI assistants (Claude, Cursor, etc.) to query MongoDB directly:
mongosh --mcp mongodb://localhost:27017 --database mydbClaude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"mongodb": {
"command": "mongosh",
"args": ["--mcp", "mongodb://localhost:27017", "--database", "mydb"]
}
}
}15 built-in tools — full CRUD, aggregation, and admin operations:
| Category | Tools |
|---|---|
| Context | mongo_prepare_context, mongo_list_datasources |
| Read | mongo_find, mongo_find_one, mongo_aggregate, mongo_count, mongo_distinct |
| Write | mongo_insert_one, mongo_insert_many, mongo_update_one, mongo_update_many |
| Delete | mongo_delete_one, mongo_delete_many |
| Admin | mongo_list_databases, mongo_list_collections, mongo_list_indexes, mongo_collection_stats, mongo_explain |
Security — configure in ~/.mongoshrc:
[mcp.security]
allow_read = true
allow_write = false
allow_delete = false
max_documents_per_query = 1000
forbidden_collections = ["system.*", "admin.*"]See MCP Documentation for details.
Comprehensive guides for all features:
- SQL Array Indexing - Access array elements with
arr[0]orarr[-1] - SQL Arithmetic Operations - Math expressions and functions
- DateTime Functions -
DATE,TIMESTAMP,CURRENT_DATE - Query EXPLAIN - Analyze query performance
- Named Queries - Save and reuse queries
- Shell Completion - Setup auto-completion
- API Reference - MongoDB method support status
- MCP Server - AI assistant integration via MCP
| Feature | Official mongosh | This Project |
|---|---|---|
| Language | JavaScript/Node.js | Rust |
| SQL Support | ❌ | ✅ Full SQL SELECT |
| Startup Time | ~500ms | <50ms |
| Memory Usage | ~50MB | ~5MB |
| Output Formats | JSON | JSON, Table, Shell |
| Named Queries | ❌ | ✅ With parameters |
| Array Indexing | MongoDB only | SQL + MongoDB |
| Auto-completion | Basic | Advanced (datasources, fields) |
| MCP Server | ❌ | ✅ 15 tools with security |
| JavaScript Runtime | ✅ Full | ❌ Not a JS shell |
Create ~/.mongoshrc or ~/.config/mongosh/config.toml:
[connection]
default_datasource = "local"
[connection.datasources]
local = "mongodb://localhost:27017"
production = "mongodb://prod.example.com:27017"
staging = "mongodb://staging.example.com:27017"
[output]
format = "pretty-json"
highlight = trueContributions are welcome! Please check out our documentation for implementation details.
Licensed under the MIT License.