0

If I issue a query in Firestore Java admin SDK and limit the number of documents to "n", I wanted to know if I will get "n" documents (assuming that there are more than n documents which satisfy the query).

The documentation doesn't specifically indicate that the number of documents returned could be lesser than the page limit even if there were more documents which satisfied the query.

Although I havent seen this behaviour in Firestore but I have observed this in Datastore when accessed from python library as explained by this SO question.

I want to make the assumption that this condition wont occur for implementing pagination in my API.

Could anybody clarify?

Sudarshan Murthy
  • 359
  • 5
  • 16
  • 1
    It won't. **[This](https://stackoverflow.com/questions/50741958/how-to-paginate-firestore-with-android)** is a recommended way in which you can paginate queries by combining query cursors with the limit() method. I also recommend you take a look at this **[video](https://www.youtube.com/watch?v=KdgKvLll07s)** for a better understanding. – Alex Mamo Dec 28 '18 at 12:33
  • Thank you for your reply. To be clear, you meant that Firestore will always return the number of documents specified in the limit clause if there are more than that number which satisfies the query. Right? Also, I cannot use document snapshot since I am doing this query from server where this is not supported. – Sudarshan Murthy Dec 28 '18 at 13:00
  • Yes, that's right. I think it should be something similar but haven't tried it yet. – Alex Mamo Dec 28 '18 at 13:29
  • Thank you @AlexMamo – Sudarshan Murthy Dec 28 '18 at 13:43
  • I answered with the (as far as I know) expected system behavior below. If that is not the behavior you see, edit your question (or post a new one) with the minimal code that reproduces the behavior you ask about. That makes it much easier to see what (for example) edge case you may be hitting. – Frank van Puffelen Dec 28 '18 at 15:52

1 Answers1

1

If there are more documents than you requested, you will get the number of documents that you requested. You will not get fewer documents in that case.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807