0

我需要进行无限滚动的 REST API 调用。我有一个通用的方法,但我似乎找不到我想要完成的正确语法。本质上,Web-App 会向我发送一个电话以获取帖子列表,这很简单。现在用户已经滚动过了我加载的前 100 个。现在,我如何MongoCursor从我离开的地方开始?

我是否发送应用程序int,他们返回,我只是做一个$cursor->find()->skip($x)

我在想,我以某种方式将我的光标发送给应用程序,然后当它准备好获得更多结果时它会将光标发送回来,我只是重新连接它并继续?

我找到了本教程 - http://artsy.github.io/blog/2013/02/15/infinite-scroll-with-mongodb/但我似乎无法掌握他们发送的参数以及为什么?

提前感谢您的帮助!

弥敦道

4

1 回答 1

0

I've found this tutorial - http://artsy.github.io/blog/2013/02/15/infinite-scroll-with-mongodb/ but I cannot seem to grasp what parameters they are sending and why?

Pagination and infinite scrolling are best implemented with range queries, which the blog post you cited demonstrates. Skip and limit are conceptually simple, and are actually quite fine if we're only dealing with a few pages, but performance starts to fall off drastically as the page counts increase into the hundreds.

When you issue a query (hopefully indexed) with a skip, MongoDB needs to go to the first result and walk forward "skip" number of times. For indexed queries, this means walking the index, which may not be entirely in memory. Contrast this to a range query that does not use skip, where our criteria requests data greater or less than that which we've last seen, MongoDB is able to jump right to the first result and we need only iterate through "limit" documents.

The following answer and blog posts explain the subject in more detail:

于 2013-08-19T17:34:20.533 回答