简体   繁体   English

derby.js如何在已排序的集合上使用$ skip和$ limit查询?

[英]derby.js How can I query using $skip and $limit on a sorted collection?

Sorry if this is a dump question but I cannot figure it out. 抱歉,这是一个转储问题,但我无法解决。

As collections grow in size, it become convenient to render a portion of the data. 随着集合大小的增长,呈现部分数据变得很方便。 For that we can something like 为此,我们可以像

model.query('items', { $skip: 30, $limit: 30 })

but what if we want to do that on a filter or a sort? 但是,如果我们想对过滤器或排序进行处理,该怎么办? I have tried 我努力了

model.query('items', { $skip: 30, $limit: 30 }, { creation_time: -1})

to mimic MongoDB .find() . 模仿MongoDB .find()

I haven't find a way to do a fetch/query on filters. 我还没有找到对过滤器进行抓取/查询的方法。 Of course I don't want to slice after .get() since that would be problematic on large collections. 当然,我不想在.get()之后进行切片,因为这在大型集合上会出现问题。 I tried to use a ref() on filter with no success. 我尝试在过滤器上使用ref()失败。 Does someone know a recipe on how to handle those situations? 有人知道如何处理这些情况的秘诀吗?

Thanks in advance. 提前致谢。

PS: I hope .fetch() hold a cursor and wait for .get() to retrieve data. PS:我希望.fetch()保持光标状态并等待.get()检索数据。

model.query('items', { $skip: 30, $limit: 30, $orderby: {creation_time: -1}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM