0
0
MongoDBquery~10 mins

One-to-one embedding pattern 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 embed the address inside the user document.

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

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

MongoDB
db.users.find({ "address.[1]": "Springfield" })
Drag options to blanks, or click blank then click option'
Astreet
Bcity
Czipcode
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Querying 'address.street' instead of 'address.city'.
Querying 'address.zipcode' when it doesn't exist.
Using 'address' without dot notation.
3fill in blank
hard

Fix the error in the update to change the street in the embedded address.

MongoDB
db.users.updateOne({ name: "Bob" }, { $set: { "address.[1]": "456 Elm St" } })
Drag options to blanks, or click blank then click option'
Azipcode
Baddress
Cstreet
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to update 'address' directly instead of 'address.street'.
Using 'city' or 'zipcode' instead of 'street'.
4fill in blank
hard

Fill both blanks to create a user document with embedded contact info.

MongoDB
db.users.insertOne({ name: "Carol", contact: { phone: [1], email: [2] } })
Drag options to blanks, or click blank then click option'
A"555-1234"
B"carol@example.com"
C12345
D"notanemail"
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers without quotes for phone or email.
Using invalid email format.
5fill in blank
hard

Fill all three blanks to query users with a specific phone number in embedded contact.

MongoDB
db.users.find({ "contact.[1]": [2], name: [3] })
Drag options to blanks, or click blank then click option'
Aphone
B"555-1234"
C"Carol"
D"555-0000"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field name instead of 'phone'.
Not using quotes around string values.
Using a different phone number or name.