Complete the code to find all documents in a MongoDB collection using Express.
app.get('/items', async (req, res) => { const items = await Item.[1](); res.json(items); });
The find method retrieves all documents from the collection.
Complete the code to find documents matching a condition in Express.
app.get('/users', async (req, res) => { const users = await User.find({ age: { [1]: 18 } }); res.json(users); });
The $gte operator finds documents where age is greater than or equal to 18.
Fix the error in the code to find a single document by ID.
app.get('/post/:id', async (req, res) => { const post = await Post.[1](req.params.id); res.json(post); });
The correct method to find a document by its ID is findById.
Fill both blanks to find documents where status is 'active' and sort by createdAt descending.
const activeItems = await Item.find({ status: [1] }).[2]({ createdAt: -1 });We filter by status 'active' and then sort by createdAt descending using sort.
Fill all three blanks to find users older than 21, select only name and email fields, and limit results to 5.
const users = await User.find({ age: { [1]: 21 } })
.[2]('name email')
.[3](5);Use $gt to find age greater than 21, select to choose fields, and limit to restrict number of results.