In reverse chronological paging queries, new data is inserted into the database during page turning, leading to the return of duplicate data. Is there any good solution? Thank you!

Source: Internet
Author: User
In reverse chronological paging queries, new data is inserted into the database, leading to duplicate data. Is there any good solution? Thank you for querying by page in reverse chronological order. some new data is inserted into the database, leading to duplicate data. Is there any good solution? Thank you!

Reply content: in reverse chronological paging queries, there are new data inserted into the db, leading to repeated data. Is there any good solution? Thank you!

Are you talking about data duplication? during page turning, someone inserts a piece of data, and the last piece of data on the first page is allocated to the second page again, changed to the first output on the second page. does this data appear twice?
In this case, we recommend that you perform the query by page on the client and add a time point during the query. Data smaller than the time when the query button is clicked will be found and then displayed on the client, in this way, new data does not affect paging, because new data is not retrieved at all. Because this is a flashback of time, new data will not be seen and data omission will not occur. When the data is loaded again, the new data will be queried.

Some time ago, I just handled a similar problem on the mobile end. let's talk about the idea of the mobile end:
1. First, it is divided into a drop-down (get the latest data) and a slide-up (get the previous data)
2. each time I slide up to obtain the previous data, I will upload an id that is used as a condition to obtain the data. If you are in reverse chronological order, you can basically determine that the id is also in reverse order. the id you just uploaded should be the smallest id in the data obtained previously. except for the first time, the data obtained each time will be smaller than this id.
3. the first time you get the data, you can get the first data in order because there is no id.

Hope to help you with your problem!

Sorry, it is the best language in the world.
My answer is based on nodejs.
But it does not affect your understanding.

------- Original answer ------

I found that coding.net APIs have two more methods.
The syntax is based on mongoose.
First, pagify. For example, for page 20, Model. find (query). skip (page * 20-20). limit (20 ).
The second is to use over-loading, specifically after. I have never developed such a feature. I'm not sure if mongodb has such a property as "after. However, it is relatively simple to rely on something in sort, Model. find (query ). sort ('-time '). where ({time :{$ gt: TIME }}). limit (20)

Are you sure you want?

It would be better if mongodb is similar to after. (Note time may crash, but id will not)
Model. find (query). sort ('-time'). after ({id: ID}). limit (20)

Add coding.net to load more request APIs

GET https://coding.net/api/activities/projects_last? Last_id = 14959187

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.