Reputation:
I have a express API and I wan't to return the documents that match the query params, as well as the number of documents.
I have the following query, and I wan't to return the following object.
const property = await Property.find(query1);
res.json({ 'results:': property.countDocuments(), property });
I get the following error
property.countDocuments is not a function
Upvotes: 0
Views: 1387
Reputation: 2388
find
returns an array of documents, so you can just use, .length
property.length
Upvotes: 0
Reputation: 2639
Just do this:
const property = await Property.countDocuments(query1);
Upvotes: 1