Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number 25 in quotes, making it a string.
Using a variable name instead of a value.
✗ Incorrect
The age field should be a number, so 25 without quotes is correct.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means less than.
Using $eq which means equal to.
✗ Incorrect
The operator $gt means 'greater than', so it finds ages above 30.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the dollar sign in the operator.
Using a wrong operator like $update.
✗ Incorrect
The correct operator to update fields is $set with a dollar sign.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using city instead of state for the second blank.
Using zipcode which is not in the example.
✗ Incorrect
The address has a street and a state field, so use 'street' and 'state'.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Use $gt for age greater than 20, and match city to "Boston".