0
0
MongoDBquery~10 mins

Querying nested fields at any depth in MongoDB - Interactive Code Practice

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' equals 'Paris'.

MongoDB
db.users.find({"address[1]city": "Paris"})
Drag options to blanks, or click blank then click option'
A.
B$
C#
D_
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$' instead of '.' to access nested fields.
Trying to access nested fields without quotes.
Using underscore '_' instead of dot '.' in field names.
2fill in blank
medium

Complete the code to find documents where the nested field 'profile.details.age' is greater than 30.

MongoDB
db.users.find({"profile.details.age": { [1]: 30 }})
Drag options to blanks, or click blank then click option'
A$ne
B$lt
C$eq
D$gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$lt' which means 'less than' instead of 'greater than'.
Using '$eq' which means 'equals' instead of a comparison operator.
Forgetting the dollar sign in the operator.
3fill in blank
hard

Fix the error in the query to find documents where 'settings.notifications.email' is true.

MongoDB
db.users.find({"settings[1]notifications[1]email": true})
Drag options to blanks, or click blank then click option'
A.
B,
C:
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas or colons instead of dots.
Using dollar signs incorrectly in field names.
Not quoting the full nested field path.
4fill in blank
hard

Fill both blanks to query documents where 'profile.contacts.phone.mobile' exists and is not null.

MongoDB
db.users.find({"profile[1]contacts[2]phone.mobile": { $exists: true, $ne: null } })
Drag options to blanks, or click blank then click option'
A.
B$
C_
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different separators between nested fields.
Using underscores or dashes instead of dots.
Leaving out separators between nested fields.
5fill in blank
hard

Fill all three blanks to query documents where 'settings.preferences.theme.color' equals 'dark'.

MongoDB
db.users.find({"settings[1]preferences[2]theme[3]color": "dark"})
Drag options to blanks, or click blank then click option'
A.
B$
C_
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using different separators like '$' or '_' instead of '.'
Mixing separators inconsistently.
Not using any separator between nested fields.