firebasegoogle-cloud-firestore

Firebase Rules for Cloud Firestore to limit maximum number of documents read in one go


I have following use case.. I don't want to allow user control document limit in cloud firestore, I want to have firebase rule restrict it.

For eg. I have a products collection, user can do pagination (max=10) per page. if its browser side, user can easily change and get all the products list. Is there any settings or rules to control this?


Solution

  • You can protect this using the query property of the request object (see docs). Basically you can write a rule with a condition on the limit:

    allow read: if request.query.limit != 10
    

    The above rule will prevent the query from going through if the limit is not set to 10.