Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find all candidates in the election collection.
MongoDB
db.election.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert() instead of find()
Using update() when you want to read data
✗ Incorrect
The find() method retrieves documents from a collection.
2fill in blank
mediumComplete the code to count how many votes a candidate named 'Alice' has.
MongoDB
db.votes.countDocuments({ candidate: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the name
Using the wrong candidate name
✗ Incorrect
We count documents where the candidate field equals 'Alice'.
3fill in blank
hardFix the error in the query to find votes where the count is greater than 100.
MongoDB
db.votes.find({ count: { [1]: 100 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt (less than) instead of $gt
Using $eq which means equal
✗ Incorrect
The operator $gt means 'greater than'.
4fill in blank
hardFill both blanks to update the vote count for candidate 'Bob' to 250.
MongoDB
db.votes.updateOne({ candidate: [1] }, { [2]: { count: 250 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $inc instead of $set
Using the wrong candidate name
✗ Incorrect
We match candidate 'Bob' and use $set to change the count to 250.
5fill in blank
hardFill all three blanks to create a dictionary with candidate names as keys and their vote counts as values, but only for counts greater than 100.
MongoDB
result = { [1]: [2] for doc in db.votes.find({ count: { [3]: 100 } }) } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using doc.name instead of doc.candidate
Using $lt instead of $gt
Swapping keys and values
✗ Incorrect
We use doc.candidate as keys, doc.count as values, and filter with $gt for counts greater than 100.