MongoDB online compiler

A mongosh-style shell (simulated) with a sample shop database. Runs in your browser.

Learn MongoDB →
shell.js
// Online MongoDB shell (simulated mongosh)
// Database "shop": customers, products, orders

db.products.find({ price: { $lt: 50 } }, { name: 1, price: 1, _id: 0 }).sort({ price: -1 })

db.orders.aggregate([
  { $unwind: '$items' },
  { $group: { _id: '$items.product', sold: { $sum: '$items.qty' } } },
  { $sort: { sold: -1 } },
  { $limit: 3 }
])
Output

Press ▶ Run or Ctrl/⌘ + Enter to run your code.

Database "shop" with collections: customers, products, orders. Each line's result is printed, like mongosh.