0
0
MongoDBquery~10 mins

Why querying nested data matters in MongoDB - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find documents where the nested field 'address.city' is 'New York'.

MongoDB
db.users.find({"address.[1]": "New York"})
Drag options to blanks, or click blank then click option'
Azip
Bstate
Ccity
Dstreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'state' or 'zip' instead of 'city' will not find the correct documents.
Forgetting to use dot notation for nested fields.
2fill in blank
medium

Complete the code to find documents where the nested array 'orders.items' contains 'apple'.

MongoDB
db.orders.find({"orders.[1]": "apple"})
Drag options to blanks, or click blank then click option'
Aitems
Bproduct
Cquantity
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'product' instead of 'items' will not match the array field.
Not using dot notation for nested arrays.
3fill in blank
hard

Fix the error in the query to find documents where 'profile.age' is greater than 30.

MongoDB
db.users.find({"profile.age": { [1]: 30 }})
Drag options to blanks, or click blank then click option'
A$lt
B$gt
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$lt' will find ages less than 30, which is incorrect here.
Using '$eq' will find ages exactly 30, not greater.
4fill in blank
hard

Fill both blanks to find documents where 'comments.rating' is at least 4 and 'comments.approved' is true.

MongoDB
db.posts.find({"comments.rating": { [1]: 4 }, "comments.approved": [2] })
Drag options to blanks, or click blank then click option'
A$gte
Bfalse
Ctrue
D$lte
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$lte' will find ratings less than or equal to 4, which is wrong here.
Setting approved to false will not find approved comments.
5fill in blank
hard

Fill all three blanks to create a projection that includes 'name', excludes '_id', and includes nested field 'profile.email'.

MongoDB
db.users.find({}, { [1]: 1, [2]: 0, [3]: 1 })
Drag options to blanks, or click blank then click option'
Aname
B_id
Cprofile.email
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Setting '_id' to 1 will include it, not exclude.
Forgetting to include 'profile.email' will omit the nested email field.