0
0
MongoDBquery~10 mins

findOne method 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 one document in the 'users' collection.

MongoDB
db.users.[1]({})
Drag options to blanks, or click blank then click option'
AupdateOne
BfindOne
CinsertOne
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using find instead of findOne returns a cursor, not a single document.
2fill in blank
medium

Complete the code to find one user with the name 'Alice'.

MongoDB
db.users.findOne({ name: [1] })
Drag options to blanks, or click blank then click option'
A'David'
B'Bob'
C'Alice'
D'Charlie'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string value.
Using the wrong name.
3fill in blank
hard

Fix the error in the code to find one document where age is 30.

MongoDB
db.users.findOne({ age: [1] })
Drag options to blanks, or click blank then click option'
A30
B"30"
C'30'
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers, which makes them strings.
Using a variable name instead of a value.
4fill in blank
hard

Fill both blanks to find one document where status is 'active' and return only the name field.

MongoDB
db.users.findOne({ status: [1] }, { [2]: 1 })
Drag options to blanks, or click blank then click option'
A'active'
Bstatus
Cname
D'inactive'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name in the projection.
Using 'inactive' instead of 'active' in the query.
5fill in blank
hard

Fill all three blanks to find one document where age is greater than 25 and return only the name and age fields.

MongoDB
db.users.findOne({ age: { [1]: [2] } }, { [3]: 1, age: 1 })
Drag options to blanks, or click blank then click option'
A$gt
B25
Cname
D$lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$lt' instead of '$gt' for greater than.
Forgetting to include the 'name' field in the projection.