MongoDB — Element & Evaluation Operators

🍃 MongoDB 7.0+ 🟢 Chapter 15 of 50 📂 Phase 03: CRUD Operations — Reading & Writing Data 📅 2026 Edition

Query documents by field existence ($exists), BSON data type ($type), regex pattern ($regex), and document field evaluation ($expr).

1Element Operators ($exists & $type)
$exists & $type Examples
// Find users who have a phone field present
db.users.find({ phone: { $exists: true } });

// Find users where age is stored as a String instead of Number
db.users.find({ age: { $type: "string" } });
2Evaluation Operators ($regex & $expr)
$regex & $expr Examples
// Case-insensitive regex search for users named "balaji"
db.users.find({ name: { $regex: /^balaji/i } });

// $expr: Compare two fields inside the SAME document!
// Find orders where spent amount exceeds total budget
db.orders.find({
  $expr: { $gt: ["$spentAmount", "$budgetLimit"] }
});
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on MongoDB 7.0+ Standards · Last updated August 2026