0
0
MongoDBquery~5 mins

find method basics in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the find() method do in MongoDB?
The find() method retrieves documents from a collection that match a query. If no query is given, it returns all documents.
Click to reveal answer
beginner
How do you use find() to get all documents from a collection?
Use db.collection.find({}). The empty curly braces mean no filter, so all documents are returned.
Click to reveal answer
intermediate
What type of value does find() return?
find() returns a cursor, which is like a pointer to the matching documents. You can iterate over it to access each document.
Click to reveal answer
intermediate
How can you limit the number of documents returned by find()?
You can chain .limit(n) after find() to get only n documents, like db.collection.find({}).limit(5).
Click to reveal answer
beginner
What does find({ age: { $gt: 25 } }) do?
It finds all documents where the age field is greater than 25. $gt means 'greater than'.
Click to reveal answer
What does db.users.find({}) return?
AAll documents in the users collection
BNo documents
COnly documents with empty fields
DAn error
Which method limits the number of documents returned by find()?
Askip()
Blimit()
Csort()
Dcount()
What type of object does find() return?
ACursor
BArray
CString
DNumber
How do you find documents where score is greater than 80?
Afind({ score: { $lt: 80 } })
Bfind({ score: 80 })
Cfind({ score: { $gt: 80 } })
Dfind({ score: { $eq: 80 } })
What happens if you call find() without parentheses like db.collection.find?
AIt returns an empty cursor
BIt returns all documents
CIt throws an error
DIt returns the function itself, not the results
Explain how the find() method works in MongoDB and how you can use it to retrieve documents.
Think about how you ask for data from a collection.
You got /4 concepts.
    Describe how to limit the number of documents returned by a find() query and why this might be useful.
    Consider when you only want a few results, not everything.
    You got /4 concepts.