使用noedjs ravendb客户端查询groupB

时间:2019-04-10 07:38:03

标签: node.js typescript ravendb

我正在尝试使用nodejs-ravendb-client在ravendb上执行groupBy查询!

const apmts = await session.query<Appointment>({ collection: "Appointments" }) .statistics(s => (stats = s)) .groupBy("client.name").all();

在打字稿编译Property 'all' does not exist on type 'IGroupByDocumentQuery<Appointment>'.ts(2339)上遇到此错误

这里有帮助吗?

1 个答案:

答案 0 :(得分:4)

文档查询的groupBy()方法返回类型为IGroupByDocumentQuery的对象 如您所见,它没有all()方法。

您可以使用selectKey()selectCount()selectSum()进行聚合,然后将其与all()链接。例如:

const { GroupByField } = require("ravendb");

const orders = await session.query({ collection: "Orders" })
    .groupBy("ShipTo.Country")
    .selectKey("ShipTo.Country", "Country")
    .selectSum(new GroupByField("Lines[].Quantity", "OrderedQuantity"))
    .all();

有关更多详细信息和示例,请参阅official documentation