iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

MongoDB Playground

MongoDB Compass is the official GUI; mongosh is the modern shell. Both ship with Atlas; both run against any cluster.

MongoDB editors and shells

EXAMPLE
// 1. mongosh - the modern shell (replaces the legacy mongo)
// Install:
//   macOS:   brew install mongosh
//   Ubuntu:  apt install mongodb-mongosh
//   Windows: scoop install mongosh

// Connect
mongosh 'mongodb+srv://app:$PASS@cluster0.xxx.mongodb.net/myapp'

// Tab-complete is great. Highlights:
db.users.find({ tier: 'pro' }).sort({ createdAt: -1 }).limit(10).explain('executionStats');
db.users.createIndex({ email: 1 }, { unique: true });
db.adminCommand({ listDatabases: 1 });

// History
mongosh --eval 'show collections' --quiet
mongosh --file batch.js


// 2. MongoDB Compass - the official GUI
// Download: https://www.mongodb.com/products/compass
// Key features:
// - Schema visualisation: sample N docs, show field types and distributions
// - Index advisor: recommended indexes for current workload
// - Aggregation pipeline builder with stage previews
// - Query profiler integration
// - Embedded mongosh tab


// 3. Studio 3T - paid, very polished
// IntelliShell with refactoring, SQL-to-MongoDB translation, schema editor


// 4. NoSQLBooster - free + paid, popular in Windows shops


// 5. VS Code - 'MongoDB for VS Code' official extension
// - Connect to a cluster
// - Run playgrounds (.mongodb.js files)
// - IntelliSense backed by your schema

// Sample playground
const db = use('myapp');
db.getCollection('orders').aggregate([
  { $match: { status: 'paid' } },
  { $group: { _id: '$customerId', total: { $sum: '$amount' } } },
  { $sort: { total: -1 } },
  { $limit: 5 },
]);


// 6. Atlas Data Explorer - web UI
// Useful for quick inspections, but it imposes query timeouts;
// reach for Compass or mongosh for anything non-trivial.


// Tips
// - Use mongosh + .js playgrounds for repeatable queries
// - Use Compass for schema discovery and index tuning
// - Never edit production data in the web Data Explorer without a query
//   that you have already run in mongosh against the same filter

Why it matters

Pair mongosh for repeatable scripts and Compass for visual analysis. The aggregation builder in Compass alone is worth the install. Avoid editing production data through any GUI - prefer scripted, reviewable updates.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// The mongosh playground runs CRUD against an in-browser collection.
db.customers.find()
Try it Yourself »

Discussion

Loading…