[英]MongoDB Stitch iOS: Pagination with skip in collection.find()
I am attempting to implement pagination using MongoDB Stitch in Swift for iOS, but I do not see skip
in the docs .我正在尝试使用 Swift 中的 MongoDB Stitch 为 iOS 实现分页,但我在文档中没有看到skip
。
The RemoteFindOptions
has sort and limit but no skip like so: RemoteFindOptions
具有排序和限制,但没有像这样的跳过:
{
"projection": <document>,
"sort": <document>,
"limit": <integer>
}
Is there no way to implement skip
with mongodb stitch for iOS?有没有办法用 iOS 的 mongodb 针迹实现skip
?
Is there no way to implement skip with mongodb stitch for iOS?有没有办法用 iOS 的 mongodb 针迹实现跳过?
For pagination, you could create a Stitch Function that returns a limited number of result using limit
.对于分页,您可以创建一个Stitch Function使用limit
返回有限数量的结果。
Essentially performing an operation similar to below:本质上执行类似于以下的操作:
db.collection.find({ "_id": 100 })
.sort({ _id: 1 })
.limit(50)
The example snippet above shows an example pagination of 50. On the client side, make sure to record the last _id
, so that you can perform another pagination request.上面的示例片段显示了一个 50 的示例分页。在客户端,请确保记录最后一个_id
,以便您可以执行另一个分页请求。 ie IE
db.collection.find({ "_id": 150 })
.sort({ _id: 1 })
.limit(50)
See also:也可以看看:
You can use aggregate
instead of find
.您可以使用aggregate
而不是find
。 For example:例如:
myCollection.aggregate([
{ $sort: { createdAt: -1 } },
{ $skip: 10 },
{ $limit: 10 }
]).toArray()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.