Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find all documents in the collection.
MongoDB
db.collection.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using SQL terms like 'select' which is not a MongoDB method.
Trying to use 'get' or 'query' which are not valid MongoDB collection methods.
✗ Incorrect
The find() method retrieves all documents from a MongoDB collection, similar to selecting rows in SQL.
2fill in blank
mediumComplete the code to insert a new document into the collection.
MongoDB
db.collection.[1]({ name: 'Alice', age: 30 })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'push' which are not MongoDB methods.
Confusing with SQL INSERT syntax.
✗ Incorrect
The insertOne() method adds a single document to a MongoDB collection.
3fill in blank
hardFix the error in the query to find documents where age is greater than 25.
MongoDB
db.collection.find({ age: { [1]: 25 } }) 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 equals.
✗ Incorrect
The operator $gt means 'greater than' in MongoDB queries.
4fill in blank
hardFill both blanks to update the age of a document where name is 'Bob'.
MongoDB
db.collection.updateOne({ name: 'Bob' }, { [1]: { age: [2] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$inc' which increments instead of setting a value.
Choosing a wrong number for age.
✗ Incorrect
The $set operator updates the value of a field. Here, age is set to 35.
5fill in blank
hardFill all three blanks to create a document with nested address information.
MongoDB
db.collection.insertOne({ name: 'Eve', address: { [1]: '123 Main St', [2]: 'Springfield', [3]: 'IL' } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'zip' instead of 'state' for the last field.
Mixing up the order of city and state.
✗ Incorrect
The document has nested fields: street, city, and state inside the address object.