MongoDB — Querying Arrays & Multikey Fields

🍃 MongoDB 7.0+ 🟢 Chapter 16 of 50 📂 Phase 04: Advanced Querying, Array & Embedded Documents 📅 2026 Edition

Learn array matching rules, $all, $elemMatch, and array length ($size) query selectors.

1Array Element Equality Matching

When you query an array field with a scalar value, MongoDB automatically matches if that value exists ANYWHERE in the array:

Array Equality Query
// Matches if "MongoDB" is present inside the skills array
db.users.find({ skills: "MongoDB" });
2Using $all and $elemMatch
$all & $elemMatch Examples
// $all: Must contain BOTH "MongoDB" AND "Node.js" in array
db.users.find({ skills: { $all: ["MongoDB", "Node.js"] } });

// $elemMatch: Matches array elements satisfying MULTIPLE conditions
db.scores.find({
  results: { $elemMatch: { score: { $gte: 80 }, subject: "Math" } }
});
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on MongoDB 7.0+ Standards · Last updated August 2026