有什么方法可以使用 createQuery 应用组和分页吗? [英] is there any way where i can apply group and pagination using createQuery?
问题描述
这样的查询,
http://localhost:3030/dflowzdata?$skip=0&$group=uuid&$限制=2
http://localhost:3030/dflowzdata?$skip=0&$group=uuid&$limit=2
和 dflowzdata 服务包含数据,如,
and dflowzdata service contains data like,
[{uuid":123456,身份证":1},{uuid":123456,身份证":2},{uuid":7890,身份证":3},{uuid":123456,身份证":4},{uuid":4567,身份证":5}]
[ { "uuid": 123456, "id": 1 }, { "uuid": 123456, "id": 2 }, { "uuid": 7890, "id": 3 }, { "uuid": 123456, "id": 4 }, { "uuid": 4567, "id": 5 } ]
在查找 Hook 之前,
Before Find Hook like,
if (query.$group !== undefined) {
let value = hook.params.query.$group
delete hook.params.query.$group
const query = hook.service.createQuery(hook.params.query);
hook.params.rethinkdb = query.group(value)
}
它给出了正确的结果但没有分页,就像我只需要两条记录但它给了我所有记录
Its gives correct result but without pagination, like I need only two records but its give me all records
结果是,
{"total":[{"group":"123456","reduction":3},{"group":"7890","reduction":1},{"group":"4567","reduction":3}],"data":[{"group":"123456","reduction":[{"uuid":"123456","id":1},{"uuid":"123456","id":2},{"uuid":"123456","id":4}]},{"group":"7890","reduction":[{"uuid":"7890","id":3}]},{"group":"4567","reduction":[{"uuid":"4567","id":5}]}],"limit":2,"skip":0}
谁能帮助我如何使用 $limit 获取正确的记录?
can anyone help me how should get correct records using $limit?
推荐答案
根据数据文档类型、在GROUPED_DATA
上调用的ReQL 命令分别对每个组进行操作.更多详情,请阅读group
文档. 所以limit
不会应用于group
的结果.
According to the documentation on data types, ReQL commands called on GROUPED_DATA
operate on each group individually. For more details, read the group
documentation. So limit
won't apply to the result of group
.
group
的页面说明:要对所有组进行操作而不是对每个组进行操作 [...],您可以使用 ungroup
将分组流或分组数据转换为代表组的对象数组.
The page for group
tells: to operate on all the groups rather than operating on each group [...], you can use ungroup
to turn a grouped stream or grouped data into an array of objects representing the groups.
因此 ungroup
将函数应用于 group
的结果:
r.db('db').table('table')
.group('uuid')
.ungroup()
.limit(2)
这篇关于有什么方法可以使用 createQuery 应用组和分页吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!