0
0
MongoDBquery~10 mins

Dot notation for embedded documents 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 all documents where the city is 'Paris'.

MongoDB
db.users.find({"address.[1]": "Paris"})
Drag options to blanks, or click blank then click option'
Astreet
Bcity
Czipcode
Dcountry
Attempts:
3 left
💡 Hint
Common Mistakes
Using the top-level field name instead of the embedded field.
Using incorrect field names like 'street' or 'zipcode' when searching for city.
2fill in blank
medium

Complete the code to update the zipcode to '75001' for users living in 'Paris'.

MongoDB
db.users.updateMany({"address.city": "Paris"}, {$set: {"address.[1]": "75001"}})
Drag options to blanks, or click blank then click option'
Astreet
Bcountry
Ccity
Dzipcode
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to update the 'city' field instead of 'zipcode'.
Using top-level fields instead of dot notation.
3fill in blank
hard

Fix the error in the query to find users with phone number '123-4567' inside the 'contact' embedded document.

MongoDB
db.users.find({"contact.[1]": "123-4567"})
Drag options to blanks, or click blank then click option'
Aphone
Bemail
Caddress
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'email' or 'address' instead of 'phone'.
Not using dot notation for embedded fields.
4fill in blank
hard

Fill both blanks to find users whose address city is 'London' and update their contact email to 'new@example.com'.

MongoDB
db.users.updateMany({"address.[1]": "London"}, {$set: {"contact.[2]": "new@example.com"}})
Drag options to blanks, or click blank then click option'
Acity
Bphone
Cemail
Dzipcode
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'phone' and 'email' fields.
Using wrong embedded document names.
5fill in blank
hard

Fill all three blanks to create a document with embedded 'profile' containing 'username' and 'age', and insert it into the 'users' collection.

MongoDB
db.users.insertOne({"profile": {"[1]": "alice123", "[2]": [3])
Drag options to blanks, or click blank then click option'
Ausername
Bage
C30
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the age value in quotes (should be a number).
Using wrong field names like 'email' instead of 'username' or 'age'.