0
0
Expressframework~5 mins

Finding and querying documents in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the find() method in Express when working with databases?
The find() method is used to search for multiple documents in a database collection that match given criteria. It returns all matching documents as an array.
Click to reveal answer
beginner
How do you query documents with a specific field value using Express and MongoDB?
You pass an object with the field and value to find(). For example, Model.find({ age: 25 }) finds all documents where the age field equals 25.
Click to reveal answer
beginner
What does findOne() do differently from find()?
findOne() returns only the first document that matches the query criteria, instead of all matching documents.
Click to reveal answer
intermediate
How can you limit the number of documents returned in a query?
You can chain the limit() method after find() to restrict how many documents are returned. For example, Model.find().limit(5) returns only 5 documents.
Click to reveal answer
beginner
What is the role of the callback or promise in querying documents with Express?
The callback or promise handles the asynchronous result of the query. It lets you access the found documents once the database finishes searching.
Click to reveal answer
Which method returns all documents matching a query in Express?
Asave()
BfindOne()
Cfind()
Dupdate()
How do you find documents where the field 'status' equals 'active'?
AModel.find({ status })
BModel.findOne('active')
CModel.find({ 'active': status })
DModel.find({ status: 'active' })
What does limit(3) do when chained after find()?
AReturns only 3 documents
BSkips 3 documents
CSorts documents by 3 fields
DDeletes 3 documents
Which method returns only the first matching document?
AfindOne()
Bfind()
CupdateOne()
DdeleteOne()
Why do queries in Express often use callbacks or promises?
ATo format the output
BBecause database operations are asynchronous
CTo speed up the query
DTo block the main thread
Explain how to find documents with a specific field value using Express.
Think about how you tell the database what to look for.
You got /3 concepts.
    Describe the difference between find() and findOne() methods.
    One returns many, the other returns one.
    You got /3 concepts.