group通过查询节点js ravendb客户端

问题描述 投票:3回答:1

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

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)

这里有什么帮助?

node.js typescript ravendb
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.