我们如何跳过mongodb针脚中的记录?

Muh*_*qan 3 mongodb-stitch

我可以在mongoDB Stitch 文档中看到limit选项,但是找不到如何跳过分页记录的方法。

在此处输入图片说明

小智 6

您可以将聚合与管道一起使用。像这样:

exports = function(arg){
  const mongodb = context.services.get("mongodb-atlas");
  const coll = mongodb.db(<dbname>).collection(<collectionname>);

  const pipeline = [
    { "$skip" : 1 },
    { "$limit": 20 }
  ];

return coll
    .aggregate(pipeline)
    .toArray();

};
Run Code Online (Sandbox Code Playgroud)