Recall & Review
beginner
What is an embedded document in MongoDB?
An embedded document is a document stored inside another document as a value of a field. It helps group related data together in one place.
Click to reveal answer
beginner
How do you query for documents where an array contains an embedded document with a specific field value?
Use dot notation with the field inside the embedded document. For example, { 'arrayField.fieldName': value } finds documents where the array has an embedded document with that field value.
Click to reveal answer
intermediate
What does the $elemMatch operator do in MongoDB queries?
$elemMatch matches documents where at least one element in an array meets multiple conditions. It helps when you want to match several criteria inside the same embedded document in the array.
Click to reveal answer
intermediate
How can you update a specific embedded document inside an array in MongoDB?
Use the positional operator $ to update the first matching embedded document. For example, db.collection.updateOne({ 'arrayField.field': value }, { $set: { 'arrayField.$.fieldToUpdate': newValue } }) updates the matched embedded document.
Click to reveal answer
intermediate
What is the difference between querying with 'arrayField.field': value and using $elemMatch?
'arrayField.field': value matches if any embedded document in the array has that field value. $elemMatch lets you specify multiple conditions that must all be true in the same embedded document.
Click to reveal answer
Which MongoDB query finds documents where an array contains an embedded document with field 'score' equal to 10?
✗ Incorrect
Using 'array.score': 10 matches documents where any embedded document in 'array' has 'score' equal to 10.
What does the $elemMatch operator allow you to do?
✗ Incorrect
$elemMatch matches array elements that satisfy all specified conditions together.
How do you update the first embedded document in an array that matches a condition?
✗ Incorrect
The positional operator $ identifies the first matching array element to update.
Which query matches documents where an array contains an embedded document with 'score' 10 and 'grade' 'A' in the same element?
✗ Incorrect
$elemMatch ensures both conditions apply to the same embedded document.
What is the result of querying { 'array.score': { $gt: 5 } }?
✗ Incorrect
This query matches if at least one embedded document in 'array' has 'score' > 5.
Explain how to query for documents where an array contains an embedded document matching multiple conditions.
Think about matching several things inside one embedded document in the array.
You got /3 concepts.
Describe how to update a specific embedded document inside an array in MongoDB.
Remember the $ operator points to the matched array element.
You got /3 concepts.