像这样查询,
http://localhost:3030/dflowzdata ?$skip=0&$group=uuid&$limit=2
dflowzdata 服务包含如下数据,
[{“uuid”:123456,“id”:1},{“uuid”:123456,“id”:2},{“uuid”:7890,“id”:3},{“uuid”:123456, “id”:4},{“uuid”:4567,“id”:5}]
在 Find Hook 之前,
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)
}
它给出了正确的结果但没有分页,就像我只需要两条记录但它给了我所有记录
结果是,
{"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 获得正确的记录?