jonlil / mongoose-paginate

mongoose-paginate
MIT License
26 stars 1 forks source link

might be a bug: paginater always return results even before/after has reach the end #3

Closed yi closed 10 years ago

yi commented 10 years ago

Hi Jonas,

I've found that might be a bug, or may be my misunderstanding.

Sorry, I haven't dive into your implementation code, because I'm currently working against a tough deadline :-(

[The problem] paginater always return results even before/after has reach the end

[Step to reproduce]

100% reproducable

Steps:

  1. git clone git@github.com:yi/node-ticket-manager.git onto a machine with mongod running
  2. npm install
  3. npm test (require mocha installed globally, by npm install mocha -g)
  4. npm start (launch the service)
  5. open http://localhost:3456/tickets in your browser
  6. click "More Older Tickets" or "More Newer Tickets" button, and wach network call in your chrom dev tool. And in Chrome log console, you would see some messages like:
[jquery.mongoose-endless-scroll::remove duplicate] id:531ec86271c506513ce83925 
[jquery.mongoose-endless-scroll::remove duplicate] id:531ec86571c506513ce83927 

These "remove duplicate" is the following quick fix I wrote to solve this problem: https://github.com/yi/node-ticket-manager/blob/master/public_src/js/jquery.mongoose-endless-scroll.coffee#L113

jonlil commented 10 years ago

Hi @yi,

I simply think it depends on how you are using the paginator.

Looks like your Ticket model sorts _id asc and in your controller you add created_at desc. This makes the paginator to both sort on _id and created_at. Have you turned on debug in mongoose to see the query sorting options?

jonlil commented 10 years ago

Installed your project and in mongoose debug i found this,

Mongoose: tickets.find({}) { 
      fields: undefined, 
      paginateKey: '_id', limit: 10, sort: { _id: 1, created_at: -1 } 
}
jonlil commented 10 years ago

When you are sorting on created_at there is no reason to sort on created_at, because MongoDB _id field contains unix_timestamp

yi commented 10 years ago

Hi Jonas, I apologize for this issue. It's my fault. The sort sentence came from legacy code which I forgot to remove.

And I also found I made another mistake that I mixed before and after. Now it works correctly.

Many thanks and I close this ticket.