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?✗ Incorrect
An empty query
{} means no filter, so all documents are returned.Which method limits the number of documents returned by
find()?✗ Incorrect
limit() restricts the number of documents returned.What type of object does
find() return?✗ Incorrect
find() returns a cursor to iterate over matching documents.How do you find documents where
score is greater than 80?✗ Incorrect
$gt means 'greater than', so this finds scores above 80.What happens if you call
find() without parentheses like db.collection.find?✗ Incorrect
Without parentheses, you get the function reference, not the query 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.