0
0
MongoDBquery~10 mins

Election process concept in MongoDB - Interactive Code Practice

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

Complete the code to find all candidates in the election collection.

MongoDB
db.election.[1]()
Drag options to blanks, or click blank then click option'
Ainsert
Bupdate
Cfind
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert() instead of find()
Using update() when you want to read data
2fill in blank
medium

Complete 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'
A'John'
B'Alice'
C'Eve'
D'Bob'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the name
Using the wrong candidate name
3fill in blank
hard

Fix 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'
A$gt
B$eq
C$lt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt (less than) instead of $gt
Using $eq which means equal
4fill in blank
hard

Fill 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'
A'Bob'
B$set
C$inc
D'Alice'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $inc instead of $set
Using the wrong candidate name
5fill in blank
hard

Fill 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'
Adoc.candidate
Bdoc.count
C$gt
Ddoc.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using doc.name instead of doc.candidate
Using $lt instead of $gt
Swapping keys and values