Introduction
Query filters help you find only the data you want from a big collection. They act like a search tool to pick matching items.
Jump into concepts and practice - no test required
{ field: value }{ age: 30 }{ price: { $lt: 50 } }{ status: { $in: ["shipped", "delivered"] } }{ name: { $regex: "^A" } }db.orders.find({ status: "shipped" }){ age: 25 }{ age: 25 }age has the value 25 exactly.score is greater than 80?$gt for 'greater than'.{ score: { $gt: 80 } } which is correct syntax. Others miss the dollar sign or use invalid syntax.{ name: "Alice", age: 30 }
{ name: "Bob", age: 25 }
{ name: "Carol", age: 30 }db.collection.find({ age: 30 }){ age: 30 } matches documents where the age field equals 30.db.collection.find({ age: $gt: 20 })$gt to be inside an object as a value for the field key.{ age: $gt: 20 } which is invalid. It should be { age: { $gt: 20 } } with curly braces around $gt: 20.status is either "active" or "pending". Which filter correctly does this?$in operator to match a field against any value in a list.{ status: { $in: ["active", "pending"] } } which is correct. { status: { $or: ["active", "pending"] } } uses invalid operator $or inside field. { $or: { status: "active", status: "pending" } } has wrong syntax for $or. { status: "active" || "pending" } uses invalid JavaScript syntax.