Try VisuaLeaf's MongoDB shell, query builder and visual aggregation builder on a real database that runs inside this page. No install, no sign-up, and nothing you type leaves your browser.
Working in SQL? Try the DuckDB playground
Embed
The playground is built from web components. A blog post, a course or your product docs can show a live shell, collection or pipeline with one script tag. The snippet follows the tool and size you picked above.
One script tag from https://visualeaf.com/playground-mongodb/widget/20261121-2019/main.js. We host the editor and the database engine, and keep them up to date. Nothing to install or build.
The database engine runs on licensed domains only, and on localhost without a key, so you can try it first. Contact us for a license key for your domain.
Put a <visualeaf-shell>, <visualeaf-collection> or <visualeaf-aggregation> where it should appear, and size it with CSS like any block. Use your own data with data-url, or the sample shop. Each reader gets their own in-memory database.
Collections as keys, documents as arrays, in Extended JSON so ObjectIds, dates and decimals keep their types.
<visualeaf-shell database="shop"
script="db.products.find()"
data='{"products": [
{"name": "Pen", "price": 2.5},
{"name": "Notebook", "price": 7}
]}'></visualeaf-shell>
init runs mongosh code once before the reader sees the widget: inserts, indexes, validators, views.
<visualeaf-shell database="shop"
init='
db.products.insertMany([
{ name: "Pen", price: NumberDecimal("2.50") }
])
db.products.createIndex({ price: 1 })
'></visualeaf-shell>
Widgets with the same shared-db share a database, like on this page. Insert in a shell, query it further down.
<visualeaf-shell shared-db="shop"
data-url="https://visualeaf.com/playground-mongodb/widget/20261121-2019/shop.json"></visualeaf-shell>
<!-- …the text of your post… -->
<visualeaf-collection shared-db="shop"
collection="products"></visualeaf-collection>
Reference
Attributes are read when the element starts, so set them before adding it to the page.
| Attribute | What it does |
|---|---|
database | The database the widget works in, and where data goes (default test). |
data | Documents to load first, Extended JSON: {"collection": [docs]} or {"db": {"collection": [docs]}}. |
data-url | The same, fetched from a URL. |
init | A shell script run once at start, before the reader sees the widget (after data). |
init-url | The same, fetched from a .js file. |
license-key | Your domain's license key (or window.MINILEAF_LICENSE_KEY = "…" once for every widget of the page). Not needed on localhost. Contact us for one. |
shared-db | Widgets on the page with the same value share one database. The first to start loads its data. |
name | The connection's name in the bar (default “Minileaf (in your browser)”). |
theme | dark or light. Without it: the reader's choice from the ☀ / ☾ toggle, else dark. |
resizable | false hides the handle readers drag to make the widget taller. |
min-height | The smallest height that handle allows, in px (default 320). |
| Attribute | What it does |
|---|---|
script | The editor's initial text. Readers run it with ⌘/Ctrl Enter, Run, Run Selected or Run to Line. |
script-url | The same, fetched from a URL. |
| Attribute | What it does |
|---|---|
collection | The collection shown first (default: the database's first, alphabetically). |
query | The initial filter, shell syntax: { price: { $lt: 10 } }. |
sort | The initial sort: { price: 1 }. |
projection | The initial projection: { name: 1, price: 1 }. |
query-builder | open shows the query builder from the start. |
view | tree (default), table or json. |
| Attribute | What it does |
|---|---|
collection | The pipeline's source collection (default: the database's first, alphabetically). Each collection opened keeps its own pipeline. |
pipeline | The initial stages, shell syntax or Extended JSON. // _NAME: … after a stage's operator names it, // _DISABLED switches it off. |
pipeline-url | The same, fetched from a URL. |
stage | The stage selected and previewed at start, from 1 (default 1; 0 for none). |
Want to experiment before putting the widgets on your site? This free license key runs them on JSFiddle through November 21, 2028. Paste it before the widget script in a fiddle's HTML panel, or start from our example below.
<script>window.MINILEAF_LICENSE_KEY = "MLK1.eyJ2IjoxLCJpZCI6InZpc3VhbGVhZi1qc2ZpZGRsZSIsImxpY2Vuc2VlIjoiSlNGaWRkbGUgZXhhbXBsZXMgKFZpc3VhTGVhZikiLCJwbGFuIjoiZnJlZSIsImRvbWFpbnMiOlsianNmaWRkbGUubmV0IiwiKi5qc2ZpZGRsZS5uZXQiLCJmaWRkbGUuanNoZWxsLm5ldCJdLCJleHBpcmVzIjoiMjAyOC0xMS0yMSIsImlzc3VlZCI6IjIwMjYtMTEtMjIifQ.26Rq0XVX3TTzvhIjV5FPckPDj6xeYmtEQCoMuQT6b4idJpMOiGi7JoCUBK--4wWHsqdIVUPJWnhsCzAXt-aZCg";</script>
The key only works on JSFiddle. For your own domain, contact us for a key.
The three tools in tabs on one shared database, a dark mode toggle and a frame you can drag wider. Copy each panel into a new fiddle (HTML, CSS, JavaScript).
<!-- Minileaf license key for JSFiddle (jsfiddle.net, *.jsfiddle.net, fiddle.jshell.net), through 2028-11-21 -->
<script>window.MINILEAF_LICENSE_KEY = "MLK1.eyJ2IjoxLCJpZCI6InZpc3VhbGVhZi1qc2ZpZGRsZSIsImxpY2Vuc2VlIjoiSlNGaWRkbGUgZXhhbXBsZXMgKFZpc3VhTGVhZikiLCJwbGFuIjoiZnJlZSIsImRvbWFpbnMiOlsianNmaWRkbGUubmV0IiwiKi5qc2ZpZGRsZS5uZXQiLCJmaWRkbGUuanNoZWxsLm5ldCJdLCJleHBpcmVzIjoiMjAyOC0xMS0yMSIsImlzc3VlZCI6IjIwMjYtMTEtMjIifQ.26Rq0XVX3TTzvhIjV5FPckPDj6xeYmtEQCoMuQT6b4idJpMOiGi7JoCUBK--4wWHsqdIVUPJWnhsCzAXt-aZCg";</script>
<script type="module" src="https://visualeaf.com/playground-mongodb/widget/20261121-2019/main.js"></script>
<div class="page">
<header class="top">
<div class="brand">
<span class="logo"><img src="https://visualeaf.com/app/media/logo-3RT6CI2M.svg" alt="VisuaLeaf"></span>
<div>
<h1>Visualeaf Playground</h1>
<p>A MongoDB-compatible database running entirely in your browser.</p>
</div>
</div>
<button id="themeToggle" class="theme-toggle" aria-label="Toggle dark mode">
<span class="icon-moon">🌙</span><span class="icon-sun">☀️</span>
</button>
</header>
<div class="resize-wrap" id="resizeWrap">
<main class="card">
<div class="card-bar">
<div class="tabs" role="tablist">
<button class="tab active" data-panel="p-shell" role="tab" aria-selected="true">
<svg viewBox="0 0 24 24"><path d="M4 7l5 5-5 5M12 18h8"/></svg>
Shell
</button>
<button class="tab" data-panel="p-query" role="tab" aria-selected="false">
<svg viewBox="0 0 24 24"><path d="M3 5h18l-7 8v6l-4-2v-4L3 5z"/></svg>
Query Builder
</button>
<button class="tab" data-panel="p-agg" role="tab" aria-selected="false">
<svg viewBox="0 0 24 24"><path d="M12 3l9 5-9 5-9-5 9-5zM3 13l9 5 9-5M3 17l9 5 9-5"/></svg>
Aggregation
</button>
</div>
</div>
<section id="p-shell" class="panel">
<visualeaf-shell
database="shop"
shared-db="shop"
data-url="https://visualeaf.com/playground-mongodb/widget/20261121-2019/shop.json"
script="// Products under 20 €, cheapest first (an editable result: try the tree or table view)
db.products.find({ price: { $lt: NumberDecimal("20") }, active: true }, { name: 1, sku: 1, price: 1, tags: 1 }).sort({ price: 1 })
// Each product with its category and supplier (two $lookup joins)
db.products.aggregate([
{ $lookup: { from: "categories", localField: "categoryId", foreignField: "_id", as: "category" } },
{ $lookup: { from: "suppliers", localField: "supplierId", foreignField: "_id", as: "supplier" } },
{ $project: { _id: 0, name: 1, price: 1, category: { $first: "$category.path" }, supplier: { $first: "$supplier.name" } } },
{ $sort: { category: 1, price: 1 } }
])
// Top 5 customers by delivered revenue, with who referred them
db.orders.aggregate([
{ $match: { status: "delivered" } },
{ $group: { _id: "$customerId", orders: { $sum: 1 }, revenue: { $sum: "$total" } } },
{ $sort: { revenue: -1 } },
{ $limit: 5 },
{ $lookup: { from: "customers", localField: "_id", foreignField: "_id", as: "customer" } },
{ $unwind: "$customer" },
{ $lookup: { from: "customers", localField: "customer.referredBy", foreignField: "_id", as: "referrer" } },
{ $project: { _id: 0, name: "$customer.name", tier: "$customer.tier", orders: 1, revenue: 1, referredBy: { $first: "$referrer.name" } } }
])
// Revenue per top-level category: order lines → product → up the category tree ($graphLookup)
db.orders.aggregate([
{ $match: { status: { $ne: "cancelled" } } },
{ $unwind: "$items" },
{ $lookup: { from: "products", localField: "items.productId", foreignField: "_id", as: "product" } },
{ $unwind: "$product" },
{ $graphLookup: { from: "categories", startWith: "$product.categoryId", connectFromField: "parentId", connectToField: "_id", as: "ancestors" } },
{ $set: { top: { $first: { $filter: { input: "$ancestors", cond: { $eq: ["$$this.parentId", null] } } } } } },
{ $group: { _id: "$top.name", lines: { $sum: 1 }, revenue: { $sum: { $multiply: ["$items.qty", "$items.unitPrice"] } } } },
{ $sort: { revenue: -1 } }
])
// The org chart under the CEO, by level ($graphLookup on reportsTo)
db.employees.aggregate([
{ $match: { title: "CEO" } },
{ $graphLookup: { from: "employees", startWith: "$_id", connectFromField: "_id", connectToField: "reportsTo", as: "reports", depthField: "level" } },
{ $unwind: "$reports" },
{ $group: { _id: "$reports.level", people: { $push: { $concat: ["$reports.name", " (", "$reports.title", ")"] } } } },
{ $sort: { _id: 1 } }
])
// Plain JavaScript works too: variables, functions, loops, template strings, print()
const since = new Date("2026-06-01")
function euros(amount) { return parseFloat(amount.toString()).toFixed(2) + " €" }
const recent = db.orders.find({ placedAt: { $gte: since }, status: { $ne: "cancelled" } }).toArray()
print(`${recent.length} orders since ${since.toISOString().slice(0, 10)}`)
const byStatus = {}
recent.forEach(o => { byStatus[o.status] = (byStatus[o.status] || 0) + 1 })
printjson(byStatus)
print("Top 3 orders:")
const topOrders = recent.sort((a, b) => parseFloat(b.total.toString()) - parseFloat(a.total.toString())).slice(0, 3)
for (const o of topOrders) {
const customer = db.customers.findOne({ _id: o.customerId })
print(` ${o.number} ${euros(o.total)} ${customer.name} (${customer.tier})`)
}
print("Gold customers:")
db.customers.find({ tier: "gold" }).toArray().forEach(c => print(` ${c.name} — ${c.addresses.map(a => a.city).join(", ")}`))"
style="width: 100%; height: 760px">
</visualeaf-shell>
</section>
<section id="p-query" class="panel" hidden>
<visualeaf-collection
database="shop"
shared-db="shop"
collection="products"
data-url="https://visualeaf.com/playground-mongodb/widget/20261121-2019/shop.json"
style="width: 100%; height: 760px">
</visualeaf-collection>
</section>
<section id="p-agg" class="panel" hidden>
<visualeaf-aggregation
database="shop"
shared-db="shop"
collection="orders"
pipeline='[
{ "$match": { "status": "delivered" } },
{ "$group": { "_id": "$customerId", "orders": { "$sum": 1 }, "revenue": { "$sum": "$total" } } },
{ "$sort": { "revenue": -1 } },
{ "$limit": 5 }
]'
data-url="https://visualeaf.com/playground-mongodb/widget/20261121-2019/shop.json"
style="width: 100%; height: 760px">
</visualeaf-aggregation>
</section>
</main>
<div class="width-handle" id="widthHandle" title="Drag to resize · double-click to reset"></div>
<div class="width-label" id="widthLabel"></div>
</div>
</div>
/* ===== Theme (same as before) ===== */
:root {
--bg: #f5f7fa;
--glow-1: rgba(34, 197, 94, .18);
--glow-2: rgba(59, 130, 246, .14);
--grid: rgba(15, 23, 42, .05);
--text: #0f172a;
--muted: #475569;
--card: #ffffff;
--border: rgba(15, 23, 42, .10);
--shadow: 0 20px 50px -20px rgba(15, 23, 42, .25);
--accent: #16a34a;
--tabs-bg: #e9eeeb;
--tab-active: #166534;
}
[data-theme="dark"] {
--bg: #0b0f14;
--glow-1: rgba(34, 197, 94, .14);
--glow-2: rgba(59, 130, 246, .12);
--grid: rgba(255, 255, 255, .04);
--text: #e5e7eb;
--muted: #94a3b8;
--card: #11161d;
--border: rgba(255, 255, 255, .08);
--shadow: 0 20px 60px -20px rgba(0, 0, 0, .7);
--accent: #22c55e;
--tabs-bg: rgba(255, 255, 255, .06);
--tab-active: #4ade80;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
color: var(--text);
background:
radial-gradient(900px 500px at 10% -10%, var(--glow-1), transparent 60%),
radial-gradient(800px 500px at 100% 0%, var(--glow-2), transparent 60%),
linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 32px 32px,
linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 32px 32px,
var(--bg);
background-attachment: fixed;
transition: background-color .3s, color .3s;
}
.page { max-width: none; margin: 0 auto; padding: 32px 24px 24px; }
/* ===== Header ===== */
.top {
display: flex; align-items: center; justify-content: space-between;
gap: 16px; margin-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
display: grid; place-items: center; width: 44px; height: 44px;
border-radius: 12px; font-size: 22px;
background: var(--card); border: 1px solid var(--border);
}
h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.theme-toggle {
width: 42px; height: 42px; border-radius: 50%; cursor: pointer; font-size: 18px;
background: var(--card); border: 1px solid var(--border); color: var(--text);
transition: transform .2s;
}
.theme-toggle:hover { transform: rotate(15deg) scale(1.05); }
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: inline; }
[data-theme="dark"] .icon-moon { display: none; }
/* ===== Card ===== */
.card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: var(--shadow);
overflow: hidden;
}
/* ===== Tabs (new) ===== */
.card-bar {
padding: 12px;
border-bottom: 1px solid var(--border);
}
.tabs {
display: inline-flex;
gap: 4px;
padding: 4px;
border-radius: 12px;
background: var(--tabs-bg);
}
.tab {
display: flex; align-items: center; gap: 8px;
padding: 8px 14px;
border: 0; border-radius: 9px;
background: transparent;
color: var(--muted);
font: 600 14px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
cursor: pointer;
transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab svg {
width: 16px; height: 16px;
fill: none; stroke: currentColor;
stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tab.active {
background: var(--card);
color: var(--tab-active);
box-shadow: 0 1px 3px rgba(0, 0, 0, .10);
}
.panel[hidden] { display: none; }
.panel > * { display: block; }
.logo img {
width: 28px;
height: 28px;
object-fit: contain;
}
.resize-wrap {
position: relative;
width: 1280px; /* starting width */
max-width: 100%; /* never wider than the window */
min-width: 360px;
margin: 0 auto;
}
.width-handle {
position: absolute;
top: 50%;
right: -16px;
transform: translateY(-50%);
width: 8px;
height: 72px;
border-radius: 4px;
background: var(--border);
cursor: ew-resize;
transition: background .15s, height .15s;
touch-action: none;
}
.width-handle:hover,
.resizing .width-handle {
background: var(--accent);
height: 96px;
}
.width-label {
position: absolute;
top: -30px;
right: 0;
padding: 3px 8px;
border-radius: 6px;
font-size: 12px;
font-variant-numeric: tabular-nums;
background: var(--card);
border: 1px solid var(--border);
color: var(--muted);
opacity: 0;
transition: opacity .15s;
pointer-events: none;
}
.resizing .width-label { opacity: 1; }
/* while dragging: stop the widgets from stealing the mouse, no text selection */
.resizing visualeaf-shell,
.resizing visualeaf-collection,
.resizing visualeaf-aggregation { pointer-events: none; }
body.no-select { user-select: none; cursor: ew-resize; }
/* ===== Footer ===== */
footer { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }
const root = document.documentElement;
const widgets = document.querySelectorAll("visualeaf-shell, visualeaf-collection, visualeaf-aggregation");
const system = matchMedia("(prefers-color-scheme: dark)");
function getSaved() { try { return localStorage.getItem("theme"); } catch { return null; } }
function save(t) { try { localStorage.setItem("theme", t); } catch {} }
function apply(theme) {
root.dataset.theme = theme;
widgets.forEach(w => w.setAttribute("theme", theme)); // widgets follow the page
}
apply(getSaved() || (system.matches ? "dark" : "light"));
system.addEventListener("change", e => { if (!getSaved()) apply(e.matches ? "dark" : "light"); });
document.getElementById("themeToggle").addEventListener("click", () => {
const next = root.dataset.theme === "dark" ? "light" : "dark";
apply(next);
save(next);
});
// Tabs
document.querySelectorAll(".tab").forEach(btn => {
btn.addEventListener("click", () => {
document.querySelectorAll(".tab").forEach(b => {
b.classList.toggle("active", b === btn);
b.setAttribute("aria-selected", b === btn);
});
document.querySelectorAll(".panel").forEach(p => {
p.hidden = p.id !== btn.dataset.panel;
});
// editors inside hidden panels sometimes need a nudge to redraw at full size
window.dispatchEvent(new Event("resize"));
});
});
// Width resize
const wrap = document.getElementById("resizeWrap");
const handle = document.getElementById("widthHandle");
const label = document.getElementById("widthLabel");
let startX = 0, startW = 0;
function setWidth(px) {
const max = wrap.parentElement.clientWidth;
const w = Math.max(360, Math.min(px, max));
wrap.style.width = w + "px";
label.textContent = Math.round(w) + " px";
window.dispatchEvent(new Event("resize")); // let the editors re-layout
}
handle.addEventListener("pointerdown", e => {
startX = e.clientX;
startW = wrap.getBoundingClientRect().width;
handle.setPointerCapture(e.pointerId);
wrap.classList.add("resizing");
document.body.classList.add("no-select");
label.textContent = Math.round(startW) + " px";
});
handle.addEventListener("pointermove", e => {
if (!handle.hasPointerCapture(e.pointerId)) return;
// card is centred, so it grows on both sides: x2 keeps the edge under the mouse
setWidth(startW + (e.clientX - startX) * 2);
});
handle.addEventListener("pointerup", e => {
handle.releasePointerCapture(e.pointerId);
wrap.classList.remove("resizing");
document.body.classList.remove("no-select");
});
// Double-click: back to full width
handle.addEventListener("dblclick", () => {
wrap.style.width = "";
window.dispatchEvent(new Event("resize"));
});
Your page's own JavaScript can drive the widgets: put a script or a query in them, run it, and read the results back. Every method waits until its widget has started. Documents come back as mongo shell text, as the query bar writes them: { "_id": ObjectId("…"), "price": NumberDecimal("0.90") }.
// Press Run on an example: it calls the method on the
// playground's widget above and shows what came back.
visualeaf-results
// Every run fires visualeaf-results, the page's and the reader's
// (Run button, paging). Run something in the playground above.
They can be called as soon as the element is defined (await customElements.whenDefined('visualeaf-shell')); await el.whenReady() waits for the widget to start.
| Element | Method | What it does |
|---|---|---|
| all | whenReady() | Resolves once the widget has started. |
| all | getResults() | The last run's result (null before the first). |
| all | event visualeaf-results | After every run, the page's or the reader's (Run button, paging), with the result as detail. |
<visualeaf-shell> | getScript() / setScript(code) | The editor's text. Setting it keeps the reader's undo. |
run(code?, {limit}?) | Runs the editor's whole script, as ▶ Run does, after putting code in it when given. Resolves when the run ends: {script, status, database, statements, output}. Each statement is {script, status, kind, documents, hasMore, namespace, value, error, prints}; kind is documents (up to limit documents, default 100), value, write or none. | |
<visualeaf-collection> | getQuery() | {database, collection, filter, sort, projection}, in shell syntax as in the query bar. |
setQuery({database?, collection?, filter?, sort?, projection?}) | Puts a query in the tab without running it. Shell syntax ('{ price: { $lt: 10 } }') or Extended JSON objects. Another collection opens as the picker opens one. | |
run(query?) | Runs the query bar's query (after setQuery(query) when given): {database, collection, filter, sort, projection, documents, skip, hasMore}, the first page. Rejects when the query is not valid or fails. | |
<visualeaf-aggregation> | getPipeline() | {database, collection, pipeline}: the pipeline in shell syntax, as the Query Code tab shows it. |
setPipeline({database?, collection?, pipeline?}) | Puts a pipeline in the builder (shell text or an array of stages) without running it; the first stage is selected and previewed. | |
run(input?) | Runs the builder's pipeline (after setPipeline(input) when given): {database, collection, pipeline, documents, skip, hasMore}, the first page. Rejects when a stage has an error or the run fails. |
The desktop app has the same shell, query builder and aggregation builder, plus schema, charts, explain plans and more, for MongoDB, PostgreSQL, MySQL, SQLite, SQL Server and more.