Typorithm · easy

Comparison Operators

mongo-comparisonmongodbcomparisonrangesets
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Comparison Operators

0%

Query Operators

Comparison operators filter by value: $gt/$gte/$lt/$lte bound ranges, $in/$nin match against a set, and $ne excludes a single value.

Range queries combine $gte (>=) and $lt (<) on the same field to express bounds like 18 <= age < 65.

$in matches a field against any value in an array, while $nin excludes documents whose field is in the array.

$ne keeps every document except those equal to the value — handy for filtering out a single status.

01

$gt/$gte/$lt/$lte bound numeric and date ranges.

02

$in matches any value in a set; $nin excludes them.

03

$ne keeps everything except one exact value.

db.users.find({ age: { $gte: 18, $lt: 65 } })
db.users.find({ role: { $in: ["admin", "editor"] } })
db.users.find({ status: { $ne: "banned" } })
db.users.find({ plan: { $nin: ["free", "trial"] } })

Read the implementation

Connect each part of the code to the concept before you type.

1. Range bounds

$gte and $lt on one field combine to express a half-open range: 18 <= age < 65.

{ $gte: 18, $lt: 65 }

2. Match any value

$in matches when the field equals any value in the array — a set membership test.

{ $in: ["admin", "editor"] }

3. Not equal

$ne matches documents whose field is anything other than the given value.

{ $ne: "banned" }

4. None of these

$nin is the inverse of $in: it excludes documents whose field is in the array.

{ $nin: ["free", "trial"] }

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Comparison Operators: Lesson & Practice · Typorithm | ApplyDjinn