0

How to know if I'm returning the last set of document/documents of a collection?

For now I keep the full document count as reference to check if I received the all the records.

I'm using skip with limit for lazy loading. Is there a better way to do this ?

1 Answers1

0

You can, as confirmed by @Abhishek Anand

  • count +
  • skip,limit

You can also fetch limit+1 documents, and only return min(n documents found, limit) This way you avoid a count, and you know you reached the end of collection whenever you don't have limit+1 documents found

grodzi
  • 5,633
  • 1
  • 15
  • 15
  • thanks for the answer. But not what I'm looking for – Shashan Sooriyahetti Dec 02 '19 at 12:57
  • Then I am not sure to understand what you are expecting. In above you know when you have reached the end of the collection. But since it is not what you expect maybe can you precise or edit your post to give an example? – grodzi Dec 02 '19 at 13:28
  • I have just read your comment on the original post. Do you mean how from the API to indicate to the consumer if he has to make another fetch or not? – grodzi Dec 02 '19 at 13:34