From 1edd63a93afde2c70d22856bcd1c74a23b61feac Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Thu, 16 Apr 2020 12:00:01 +0800 Subject: [PATCH] Update cf-database.md --- docs/uniCloud/cf-database.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/uniCloud/cf-database.md b/docs/uniCloud/cf-database.md index 896dca8a..38f0f7ae 100644 --- a/docs/uniCloud/cf-database.md +++ b/docs/uniCloud/cf-database.md @@ -268,10 +268,10 @@ let res = await collection.doc('doc-id').set({ ### 添加查询条件 collection.where() -参数 -设置过滤条件 -where 可接收对象作为参数,表示筛选出拥有和传入对象相同的 key-value 的文档。比如筛选出所有类型为计算机的、内存为 8g 的商品: +**在聚合操作中请使用match** + +设置过滤条件,where 可接收对象作为参数,表示筛选出拥有和传入对象相同的 key-value 的文档。比如筛选出所有类型为计算机的、内存为 8g 的商品: ```js let res = await db.collection('goods').where({ @@ -304,7 +304,6 @@ db.collection('user').where({ collection.count() -参数 ```js let res = await db.collection('goods').where({ category: 'computer', @@ -314,6 +313,17 @@ let res = await db.collection('goods').where({ }).count() ``` +**注意** + +使用阿里云时,count必须搭配where使用,此问题阿里云正在修复。如果要count所有记录可以使用一个必然满足的条件,比如下面这样: + +```js +const dbCmd = db.command +let res = await db.collection('goods').where({ + _db: dbCmd.exists(true) +}).count() +``` + 响应参数 | 字段 | 类型 | 必填 | 说明 | -- GitLab