云函数端Aggregate聚合操作limit默认20条限制
发布于 4 年前 作者 juan96 4119 次浏览 来自 分享

云函数端 聚合 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>



![](https://image.wxopen.club/content_188b83a4-cd5c-11ea-96a2-001a7dda7111.png)
<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>



![](https://image.wxopen.club/content_18a685b6-cd5c-11ea-bb7e-001a7dda7111.png)
3 回复

我今天中午刚为了这个1000限制优化了下逻辑代码,现在告诉我可以查询10000条了

自给自足丰衣足食

回到顶部