0
0
MongoDBquery~10 mins

Why document design matters in MongoDB - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert a document into the collection.

MongoDB
db.users.insertOne({ name: "Alice", age: [1] })
Drag options to blanks, or click blank then click option'
Anull
B"25"
Cage
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number 25 in quotes, making it a string.
Using a variable name instead of a value.
2fill in blank
medium

Complete the code to find documents where the age is greater than 30.

MongoDB
db.users.find({ age: { [1]: 30 } })
Drag options to blanks, or click blank then click option'
A$gt
B$lt
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means less than.
Using $eq which means equal to.
3fill in blank
hard

Fix the error in the update query to set the city field.

MongoDB
db.users.updateOne({ name: "Bob" }, { [1]: { city: "Paris" } })
Drag options to blanks, or click blank then click option'
A$update
Bset
C$set
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the dollar sign in the operator.
Using a wrong operator like $update.
4fill in blank
hard

Fill both blanks to create a document with an embedded address object.

MongoDB
db.users.insertOne({ name: "Eve", address: { [1]: "123 Main St", [2]: "NY" } })
Drag options to blanks, or click blank then click option'
Astreet
Bcity
Cstate
Dzipcode
Attempts:
3 left
💡 Hint
Common Mistakes
Using city instead of state for the second blank.
Using zipcode which is not in the example.
5fill in blank
hard

Fill all three blanks to query documents with age greater than 20 and city equals 'Boston'.

MongoDB
db.users.find({ age: { [1]: 20 }, address: { [2]: [3] } })
Drag options to blanks, or click blank then click option'
A$gt
Bcity
C"Boston"
D$lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt for age.
Not putting Boston in quotes.
Using wrong field name instead of city.