Recall & Review
beginner
What is an array in a MongoDB document?
An array in a MongoDB document is a list of values stored in a single field. It can hold multiple items like numbers, strings, or even other documents.
Click to reveal answer
beginner
How do you store multiple phone numbers for a user in MongoDB?
You store multiple phone numbers as an array inside the user's document, for example: { "phoneNumbers": ["123-4567", "987-6543"] }.
Click to reveal answer
intermediate
How can you query documents where an array contains a specific value?
You can query using the field name and the value inside the array, like: { "tags": "mongodb" } to find documents where the 'tags' array contains 'mongodb'.
Click to reveal answer
beginner
What happens if you add a document with an empty array field?
The document stores the field with an empty array, meaning the field exists but has no items. This is useful to show the field is expected but currently empty.
Click to reveal answer
intermediate
Can arrays in MongoDB hold different data types together?
Yes, arrays in MongoDB can hold mixed data types like strings, numbers, and even nested documents all in the same array.
Click to reveal answer
How do you represent multiple values in a single field in MongoDB?
✗ Incorrect
Arrays allow storing multiple values in one field in MongoDB documents.
Which query finds documents where the 'colors' array contains 'red'?
✗ Incorrect
Querying with { colors: 'red' } matches documents where 'colors' array contains 'red'.
Can MongoDB arrays contain nested documents?
✗ Incorrect
MongoDB arrays can hold nested documents as elements.
What does an empty array field in a document mean?
✗ Incorrect
An empty array means the field is present but contains no elements.
Is it possible to store different data types in the same array in MongoDB?
✗ Incorrect
MongoDB arrays can hold mixed data types including strings, numbers, and documents.
Explain how arrays are used in MongoDB documents and give a simple example.
Think about how you store a list of items like phone numbers or tags.
You got /3 concepts.
Describe how to query documents where an array contains a specific value.
Remember you can query by just specifying the value inside the array field.
You got /3 concepts.