Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 pageByLastId 进行降序排序时发现一个问题 #1

Open
modood opened this issue Aug 19, 2015 · 0 comments
Open

使用 pageByLastId 进行降序排序时发现一个问题 #1

modood opened this issue Aug 19, 2015 · 0 comments

Comments

@modood
Copy link

modood commented Aug 19, 2015

表结构

OperatingRecordSchema = new Schema({
  product_id: { // 商品ID
    type: Schema.ObjectId,
    required: true,
    index: true
  },
  product_name: String, //商品名称
  count: Number, // 商品的数量
  operator: String, //操作人
  operate_status: { // 操作状态【入库 0 | 出库 1 】
    type: Number,
    required: true
  },
  user_to_id: { // 收货人id  from contact
    type: Schema.ObjectId,
    index: true
  },
  user_to_name:String,
  user_to_address: String,
  user_to_phone: String,

  user_name: String, //发货人姓名
  user_id: { // 用户的id
    type: Schema.ObjectId,
    // required: true,
    index: true
  },
  created_at: {
    type: Date,
    default: Date.now
  }
});

现在数据库有10条数据(按顺序创建的)

PageSize为5, 根据 created_at 升序排序时一切正常:

使用 top 第一次加载5条:

1
2
3
4
5  <-- last_index

点击加载更多(使用 pageByLastId 再加载5条):

1
2
3
4
5
6
7
8
9
10

当根据 created_at 降序排序时:

使用 top 第一次加载5条:

10
9
8
7
6  <-- last_index

点击加载更多(使用 pageByLastId 再加载5条)出现了问题:

排序变成了这样:

10
9
8
7
6
10
9
8
7

这次使用 pageByLastId 只加载出了 4条数据,而且 10,9,8,7 重复地取出来了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant