簡體   English   中英

如何計算 mongodb/express 中的文檔數

[英]How to count documents in mongodb/express

我有一個快遞 API 並且我不想返回與查詢參數匹配的文檔以及文檔數量。

我有以下查詢,我不想返回以下 object。

  const property = await Property.find(query1);
  res.json({ 'results:': property.countDocuments(), property });

我收到以下錯誤

property.countDocuments 不是 function

只需這樣做:

const property = await Property.countDocuments(query1);

find返回一個文檔數組,因此您可以使用.length property.length

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM