小程序云开发服务器端代码 Query.aggregate 提示 is not a function
发布于 6 年前 作者 mingduan 4780 次浏览 来自 官方Issues

小程序云开发服务器端代码使用 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语法是什么情况下使用的?

1 回复

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

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

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

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

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

回到顶部