Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a document into the collection.
MongoDB
db.collection.insertOne({ name: "Alice", age: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes makes them strings.
Using undefined variables instead of values.
✗ Incorrect
The age field should be a number, so 25 without quotes is correct.
2fill in blank
mediumComplete the code to find all documents where age is greater than 20.
MongoDB
db.collection.find({ age: { [1]: 20 } }) 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.
✗ Incorrect
The operator $gt means 'greater than'.
3fill in blank
hardFix the error in the query to find documents with name 'Bob'.
MongoDB
db.collection.find({ name: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string values.
Using single quotes which may cause errors in some shells.
✗ Incorrect
String values in MongoDB queries must be in double quotes.
4fill in blank
hardFill both blanks to create a document with a nested address field.
MongoDB
db.collection.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
Mixing up city and state fields.
Using invalid field names.
✗ Incorrect
The nested document has fields 'street' and 'state' for the address.
5fill in blank
hardFill all three blanks to query documents where age is less than 30 and city is 'LA'.
MongoDB
db.collection.find({ [1]: { [2]: 30 }, city: [3] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt.
Not quoting string values.
Mixing up field names.
✗ Incorrect
The query filters documents where age is less than 30 and city equals 'LA'.