我有一个express API,我不想返回与查询参数匹配的文档,以及文档的数量。
我有下面的查询,我不想返回下面的对象。
const property = await Property.find(query1);
res.json({ 'results:': property.countDocuments(), property });
我得到以下错误
Property.CountDocuments不是函数
只要这样做:
const property = await Property.countDocuments(query1);
find
返回一个文档数组,因此您可以只使用,.length
property.length