我有一个Mongo DB数据库,里面有80个左右的文档。我只想显示从第12个文档到第24个文档,或从第3个文档到第50个文档,等等。
我的意思是,因为我有80个文档,所以我只想显示一定范围的文档。例如,数据库中的第12个文档一直到第24个文档。
我该如何高效地做到这一点呢?
谢谢
发布于 2020-08-16 04:10:16
您可以使用skip和limit
skip
limit
const perPage = 12; let page = 0; // Select the 1st - 12th document await this.SomeModel .find(query) .skip(page*perPage) .limit(perPage); page = 1; // Select the 13th - 24th document await this.SomeModel .find(query) .skip(page*perPage) .limit(perPage);
https://stackoverflow.com/questions/63430123
相似问题