Mongodb paging query data duplication

(The essence of learning is not what knowledge is remembered, but what it triggers your thinking - Michael Sandel)

insert image description here

Limitations of mongodb sorting

Related Links

  • Sort up to 32 keys
  • sort consistency

The sorting consistency means that if the sorted field values ​​are repeated, data duplication may occur when performing pagination queries, that is, the first page and the second page may have the same data.

Then there are two solutions to this problem

  • Use unique values ​​for sorting, such as id, etc.
  • Use the _id generated by mongodb by default for sorting
db.restaurants.find().sort( {
    
     "borough": 1, "_id": 1 } )

Guess you like

Origin blog.csdn.net/qq_42427109/article/details/132210690