[英]How to count documents in mongodb/express
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.我有一个快递 API 并且我不想返回与查询参数匹配的文档以及文档数量。
I have the following query, and I wan't to return the following object.我有以下查询,我不想返回以下 object。
const property = await Property.find(query1);
res.json({ 'results:': property.countDocuments(), property });
I get the following error我收到以下错误
property.countDocuments is not a function
property.countDocuments 不是 function
Just do this:只需这样做:
const property = await Property.countDocuments(query1);
find
returns an array of documents, so you can just use, .length
property.length find
返回一个文档数组,因此您可以使用.length
property.length
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.