小程序服务端count方法获取集合总记录数

发布于 6 年前作者 nzhou7002 次浏览最后编辑 6 年前来自 ask
  • 当前 Bug 的表现(可附上截图)

  • 预期表现

  • 复现路径

  • 提供一个最简复现 Demo

eg:

错误写法:const num=await db.collection(“user”).count().total;

console.log(num);

结果为undefined;

正确写法:const result=await db.collection(“user”).count();

                 const num=result.total;

                  console.log(num);

                  结果可以正常取出集合中的总记录数;这是什么原因,非要用两句话才能获得结果,而一句话在末尾取toal值就为undefined;

1 回复
fenggang
fenggang1 楼5 年前

await的原因。

const num=(await db.collection(“user”).count()).total