From ccb61d0ab2761c58d708a43a68fa66705a3c827f Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Fri, 30 Dec 2022 18:25:19 +0800 Subject: [PATCH] docs: update aggregate --- docs/uniCloud/cf-database-aggregate.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/uniCloud/cf-database-aggregate.md b/docs/uniCloud/cf-database-aggregate.md index 48e2f0031..67c4802e8 100644 --- a/docs/uniCloud/cf-database-aggregate.md +++ b/docs/uniCloud/cf-database-aggregate.md @@ -38,6 +38,29 @@ exports.main = async function(){ } ``` +将上述两个用法修正为正确用法分别如下: + + +```js +const db = uniCloud.database() +const collection = db.collection('test') +exports.main = async function(){ + const aggregate = collection.aggregate() // 每次执行云函数会有独立的聚合实例 + const res = await aggregate.match({a:1}).end() + return {res} +} +``` + +```js +const db = uniCloud.database() +const collection = db.collection('test') +exports.main = async function(){ + const res1 = await collection.aggregate().match({a:1}).end() // 两个请求分别调用aggregate方法产生聚合实例 + const res2 = await collection.aggregate().match({a:2}).end() + return {res1, res2} +} +``` + ## 聚合表达式@aggregate-expression 表达式可以是字段路径、常量、或数据库运算方法。表达式可以嵌套表达式。 -- GitLab