Limit a number of documents in a subcollection in firestore rules

后端 未结 1 1916
栀梦
栀梦 2020-12-18 06:58

My request is pretty simple in appearence : limiting the number of documents in a subcollection using Firestore Rules.

I already know that it is possible to know the

1条回答
  •  抹茶落季
    2020-12-18 07:31

    In a general sense (both in database rules and client SDKs) there is no way to know the size of a collection. You have the option of recording that yourself in another document that's managed by Cloud Functions. But bear in mind also that a document is limited to 10 writes per second, so busy collections might not be able to keep in sync with the document used to record size.

    You could also use Cloud Functions to remove documents from a collection in response to new documents being added, but the limitation of now knowing the size of the collection will be problematic. It might be better to find a way to query to find documents to delete (for example, by timestamp) rather than depending on the size of the collection.

    0 讨论(0)
提交回复
热议问题