C100DEV MongoDB Overview and Document Model Practice Question
A developer is reviewing a MongoDB collection that stores blog posts. Each post document has a field 'tags' that is an array of strings. The developer wants to find all posts that have both 'mongodb' and 'database' in the tags array. Which query correctly retrieves these documents?
⚠ Common exam trap
Watch out — candidates often confuse $all with $in; $in matches any of the values, while $all requires all values to be present.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
{ tags: { $all: ["mongodb", "database"] } }
The $all operator is designed to match arrays that contain all specified elements, making it the correct choice for finding posts with both 'mongodb' and 'database' tags. The $in operator matches any of the elements, the exact array match is too strict, and $elemMatch is for conditions on a single element. Only $all satisfies the requirement.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
{ tags: { $in: ["mongodb", "database"] } }
Why it's wrong here
The $in operator matches documents where the array field contains at least one of the specified elements. It would return posts that have either 'mongodb' or 'database' (or both), but not necessarily both. This does not satisfy the requirement to find posts with both tags. It is too broad.
- ✓
{ tags: { $all: ["mongodb", "database"] } }
Why this is correct
The $all operator matches documents where the array field contains all the specified elements. In this case, it will return posts that have both 'mongodb' and 'database' in the tags array, regardless of order or additional elements. This is the correct and efficient way to query for multiple elements in an array.
- ✗
{ tags: { $elemMatch: { $eq: "mongodb", $eq: "database" } } }
Why it's wrong here
The $elemMatch operator is used to match array elements that satisfy multiple conditions on a single element. Here, it attempts to match a single element that is both 'mongodb' and 'database', which is impossible. This query will not return any documents. $elemMatch is not suitable for matching multiple distinct elements.
- ✗
{ tags: ["mongodb", "database"] }
Why it's wrong here
This query matches documents where the tags array is exactly equal to the array ["mongodb", "database"], including order and length. It would not match posts that have additional tags or a different order. This is too restrictive and unlikely to match the desired documents.
About these practice questions
Courseiva writes every C100DEV question from scratch — 259 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official MongoDB exam blueprint
This C100DEV practice question is part of Courseiva's free MongoDB certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the C100DEV exam.