Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// $elemMatch — at least one element must match ALL conditions db.students.find({ scores: { $elemMatch: { subject: "math", score: { $gte: 90 } } } }) // $all — array must contain all specified values db.posts.find({ tags: { $all: ["mongodb", "nodejs"] } }) // $size — array has exactly N elements db.users.find({ hobbies: { $size: 3 } }) // $exists — field must be present (or absent) db.users.find({ deletedAt: { $exists: false } }) db.users.find({ phoneNumber: { $exists: true } }) // $type — filter by BSON type db.records.find({ value: { $type: "string" } }) db.records.find({ value: { $type: ["int", "double"] } }) // $regex — pattern match on a string field db.users.find({ email: { $regex: /^alice/i } }) // Dot-notation — query nested document fields db.users.find({ "address.city": "New York" }) // Query specific array index db.scores.find({ "grades.0": { $gte: 80 } })
Result
Open