0
0
MongoDBquery~10 mins

One-to-many referencing 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 find all orders for a customer with ID 123.

MongoDB
db.orders.find({ customer_id: [1] })
Drag options to blanks, or click blank then click option'
A123
B"123"
C"customer_id"
DObjectId("123")
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number when the ID is stored as a number.
Using ObjectId when the ID is a simple number.
2fill in blank
medium

Complete the code to insert a new order referencing customer ID 456.

MongoDB
db.orders.insertOne({ order_id: 1, customer_id: [1], items: 0 })
Drag options to blanks, or click blank then click option'
A456
B"customer_456"
CObjectId("456")
D"456"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for customer_id.
Using ObjectId when not appropriate.
3fill in blank
hard

Fix the error in the query to find orders for customer ID 789.

MongoDB
db.orders.find({ customer_id: [1] })
Drag options to blanks, or click blank then click option'
A"789"
B789
CObjectId("789")
Dcustomer_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string or ObjectId instead of a number.
Using the field name as a value.
4fill in blank
hard

Fill both blanks to create a query that finds orders with more than 2 items for customer ID 101.

MongoDB
db.orders.find({ customer_id: [1], items: { $[2]: 2 } })
Drag options to blanks, or click blank then click option'
A101
Bgt
Cgte
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gte instead of $gt for strictly more than 2.
Using the wrong customer ID.
5fill in blank
hard

Fill all three blanks to update the customer name for customer ID 202.

MongoDB
db.customers.updateOne({ _id: [1] }, { $[2]: { name: [3] } })
Drag options to blanks, or click blank then click option'
A202
Bset
C"Alice"
D"202"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string "202" instead of number 202 for _id.
Using wrong update operator like $update.
Not quoting the new name string.