0
0
MongoDBquery~10 mins

Denormalization trade-offs 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 denormalized document with embedded address.

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

Complete the code to update the embedded address city field in a denormalized document.

MongoDB
db.customers.updateOne({ name: "Alice" }, { $set: { "address.[1]": "Shelbyville" } })
Drag options to blanks, or click blank then click option'
Astreet
Bcountry
Czipcode
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Updating the wrong field like street or zipcode.
Not using dot notation to access nested fields.
3fill in blank
hard

Fix the error in the query to find customers with a specific city in their embedded address.

MongoDB
db.customers.find({ "address": [1] })
Drag options to blanks, or click blank then click option'
A{ city: "Shelbyville" }
B"Shelbyville"
C["Shelbyville"]
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string or array instead of an object for the embedded document.
Using null which matches no documents.
4fill in blank
hard

Fill both blanks to create a query that finds customers with an embedded address city of "Shelbyville".

MongoDB
db.customers.find({ "[1]": "[2]" })
Drag options to blanks, or click blank then click option'
Aaddress.city
BShelbyville
Caddress.street
DSpringfield
Attempts:
3 left
💡 Hint
Common Mistakes
Querying the wrong nested field like address.street.
Using the wrong city name.
5fill in blank
hard

Fill all three blanks to update the embedded address zipcode to "12345" for customer "Alice".

MongoDB
db.customers.updateOne({ name: "[1]" }, { $set: { "address.[2]": "[3]" } })
Drag options to blanks, or click blank then click option'
AAlice
Bzipcode
C12345
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong customer name.
Updating the wrong field like city instead of zipcode.
Setting an incorrect zipcode value.