收藏
回答

小程序云开发服务器端代码 Query.aggregate 提示 is not a function

框架类型 问题类型 终端类型 AppID 基础库版本
小程序 Bug 工具 wxd9ee3c428b3fbec8 2.9.3

小程序云开发服务器端代码使用 Query.aggregate 语法发起聚合操作时提示 is not a function。

Collection.aggregate情况下:

cloud.database(...).collection(...).aggregate 可以正常调用

Query.aggregate情况下:

cloud.database(...).collection(...).where(...).orderBy(...).aggregate is not a function

经测试 一下两种情况同样报错:

cloud.database(...).collection(...).where(...).aggregate is not a function

cloud.database(...).collection(...).orderBy(...).aggregate is not a function

=========================更新================================

经测试,在使用聚合查询时对collection的where和orderBy操作应该放在aggregate后通过match和sort来实现,而lookup对关联查询的子表的条件和排序则需要通过pipeline的match和sort来实现。.

结论就是这样,但是依旧不清楚文档手册中的Query.aggregate语法是什么情况下使用的?

最后一次编辑于  2019-11-21
回答关注问题邀请回答
收藏

1 个回答

  • 老张
    老张
    2019-11-21

    报错的两种都是错误用法,没这样写的。

    cloud.database(...).collection(...).where(...).aggregate 改成:

    cloud.database(...).collection(...).aggregate().match().end()

    cloud.database(...).collection(...).orderBy(...).aggregate 改成:

    cloud.database(...).collection(...).aggregate().sort().end()

    2019-11-21
    有用
    回复 2
    • Ryan.C
      Ryan.C
      2019-11-21
      刚我自己已经发现了实际效果是这样的,但是我同时想对目标链接的数据集也进行条件限制和排序,在线手册明明写了有“Query.aggregate”语法,给人产生了歧义
      2019-11-21
      回复
    • Ryan.C
      Ryan.C
      2019-11-21
      lookup子查询已经用pipeline实现 ,aggregate聚合操作的逻辑总算是理清了 谢谢您的回复
      2019-11-21
      回复
登录 后发表内容
问题标签