0
0
MongoDBquery~10 mins

Embedded documents (nested objects) 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 insert a document with an embedded address object.

MongoDB
db.users.insertOne({ name: "Alice", address: [1] })
Drag options to blanks, or click blank then click option'
A"123 Main St, Springfield"
B["123 Main St", "Springfield"]
C{ street: "123 Main St", city: "Springfield" }
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using an array instead of an object for the embedded document.
Using a string instead of an object for the embedded document.
2fill in blank
medium

Complete the query to find users living in the city 'Springfield'.

MongoDB
db.users.find({ "address.[1]": "Springfield" })
Drag options to blanks, or click blank then click option'
Astreet
Bcity
Czip
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong nested key like 'street' or 'zip'.
Not using quotes around the dot notation field.
3fill in blank
hard

Fix the error in the update query to set the user's street to '456 Elm St'.

MongoDB
db.users.updateOne({ name: "Alice" }, { $set: { "address.[1]": "456 Elm St" } })
Drag options to blanks, or click blank then click option'
Astreet
Baddress
Czip
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to update the whole address object instead of just the street.
Using the wrong nested key like 'city' or 'zip'.
4fill in blank
hard

Fill both blanks to create a document with a nested contact object containing email and phone.

MongoDB
db.contacts.insertOne({ name: "Bob", contact: { [1]: "bob@example.com", [2]: "123-456-7890" } })
Drag options to blanks, or click blank then click option'
Aemail
Bphone
Caddress
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using keys like 'address' or 'name' inside the contact object.
Mixing up the keys for email and phone.
5fill in blank
hard

Fill all three blanks to query documents where the nested 'contact.email' ends with '@example.com'.

MongoDB
db.contacts.find({ "contact.[1]": { [2]: [3] } })
Drag options to blanks, or click blank then click option'
Aphone
B$regex
C"@example.com$"
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong nested key like 'phone'.
Using an incorrect operator instead of $regex.
Not using quotes around the regex pattern.