云函数端Aggregate聚合操作limit默认20条限制
云函数端 聚合 Aggregate
-
经过以下代码验证:
// test_record 集合中 openid 为 test user openid 的实际上有超过20条数据的 db .collection('test_record') .aggregate() .match({ _openid: 'test user openid', }) .end();
最后实际只返回了20条数据,所以说在云函数端如果某些接口返回确定以及肯定超过20条的话,还是老老实实加上
.limit(100)
‘保命’吧。 -
改成如下代码即可超过默认20条的限制:
db .collection('test_record') .aggregate() .match({ _openid: 'test user openid', }) .limit(100) // important .end();
-
上限可以达到1万条数据
经过 stop eating 同学点拨,原来可以直接淦到10000
参考文档
<a href="https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.limit.html#%E8%AF%B4%E6%98%8E" rel="noopener" target="_blank">Collection.limit(value: number): Collection</a>

<a href="https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/database/read.html#%E8%8E%B7%E5%8F%96%E4%B8%80%E4%B8%AA%E9%9B%86%E5%90%88%E7%9A%84%E6%95%B0%E6%8D%AE" rel="noopener" target="_blank">获取一个集合的数据</a>
