提交 8410d4f9 编写于 作者: 雪洛's avatar 雪洛

docs: uniCloud database aggregate

上级 b98f852a
......@@ -2067,6 +2067,31 @@ db.collection('scores').aggregate()
**注意:聚合操作实例仅用于查询,不可执行增删改操作。在聚合操作实例上只能使用聚合操作方法,不能使用where/orderBy等基础方法,where需改为match,orderBy应使用sort实现,细节请阅读下方聚合操作文档。**
云函数中使用时切勿复用aggregate实例,容易引发Bug。
以下两种写法均为错误示例:
```js
const db = uniCloud.database()
const collection = db.collection('test')
const aggregate = collection.aggregate() // 云函数实例复用时,此聚合实例也会复用,导致Bug
exports.main = async function(){
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 aggregate = collection.aggregate() // 此聚合实例分别在两个请求内使用,导致Bug
const res1 = await aggregate.match({a:1}).end()
const res2 = await aggregate.match({a:2}).end()
return {res1, res2}
}
```
### 聚合表达式
表达式可以是字段路径、常量、或聚合操作符。表达式可以嵌套表达式。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册