🗡️ sift.js Trainer

Learn MongoDB-style query syntax by writing real queries against a live dataset — powered by the actual sift library, running entirely in your browser.

Dataset:
📜 The dataset (click to expand)

🃏 Cheat Sheet — quick lookup

Mental model in one line: a query is a JSON object, and every $operator is a little yes/no test. No $ on a key = "this field equals this value". A $ key = "apply this test". Stack keys and they all must pass (implicit AND).

The 30-second rules

You write…It means…
{ field: value }field equals value (implicit $eq)
{ field: { $op: x } }run test $op against field
{ a: 1, b: 2 }a===1 AND b===2 (all keys must pass)
{ "a.b.c": x }dive into nested objects with dots…
{ "tags.name": x }…and it auto-searches every element if the path hits an array
{ field: (v) => bool }escape hatch: any function as a predicate

Operator quick reference

✅ = implemented in sift. Mnemonics in the last column.

OperatorMeaningMini exampleRemember it as…
$eq / $neequals / not equals{ rank: { $ne: "C" } }"EQuals / Not Equal"
$gt $gte $lt $lte>, ≥, <, ≤{ level: { $gte: 64 } }Greater/Less Than (+E = "or Equal")
$in / $ninis / isn't in a list{ rank: { $in: ["S","A"] } }"IN the guest list / Not IN"
$and $or $norall / any / none of these{ $or: [ {rank:"S"}, {gold:{$lt:100}} ] }boolean glue (takes an array)
$notinvert a single test{ element: { $not: { $eq: "ice" } } }"flip it"
$existsfield present (or not){ gold: { $exists: false } }"is the field even there?"
$typevalue is of a type{ joined: { $type: Date } }pass a constructor or "string"…
$regex (+$options)string matches pattern{ name: { $regex: "^Z", $options: "i" } }"text search"
$modvalue % divisor === remainder{ level: { $mod: [2, 0] } }[divisor, remainder] → even=[2,0]
$sizearray has exactly N elements{ potions: { $size: 2 } }"how long is the array?"
$allarray contains all of these{ tags: { $all: ["tank","veteran"] } }"must have ALL"
$elemMatch≥1 array element matches a sub-query{ potions: { $elemMatch: { kind:"heal", qty:{$gte:5} } } }"one element satisfies the WHOLE inner query"
$whereraw JS expression (⚠ eval){ $where: "this.level > 80" }last resort

Not in sift: $expr, $jsonSchema, bitwise ($bitsAllSet…), geospatial ($near…).

Ready to practice? Hit a difficulty tab above. Each question wants a query object — type it in the box and press Check (or Ctrl/⌘+Enter). You're graded on whether your query selects the right hunters, so many different correct queries pass.

🟢 Beginner — the fundamentals

Equality, comparisons, $in, and stacking conditions. These are ~80% of real-world queries.

0 / 0

🟡 Intermediate — combining logic

$and/$or/$nor, $nin, $regex, $exists, $size — composing real filters.

0 / 0

🔴 Advanced — arrays & nesting

$elemMatch, $all, dot-paths into arrays, $not, $mod, dates — the tricky stuff.

0 / 0

🧪 Sandbox — free exploration

Write any query object and run it against the full roster. Great for testing an idea before answering a quiz.


Runs the real sift v17.1.3 bundle, inlined — works offline. Your progress is saved in this browser. Companion to the sift.js Internal Guide.