Cost optimization patterns for Firebase Cloud Firestore: fetching documents over collections

后端 未结 1 701
深忆病人
深忆病人 2021-01-05 19:13

My goal is to optimize my app\'s architecture for cost when using Firebase Cloud Firestore. I understand Cloud Firestore\'s pricing model is on a per read/write basis. So I\

相关标签:
1条回答
  • 2021-01-05 20:16

    The idea of having a "master document" is a good one because you'll be able to make a single write operation even if you change multiple properties within it but there is a problem regarding a constraint, documents have limits. So there are some limits when it comes to how much data you can put into a document. According to the official documentation regarding usage and limits:

    Maximum size for a document: 1 MiB (1,048,576 bytes)

    As you can see, you are limited to 1 MiB total of data in a single document. When we are talking about storing text, you can store pretty much but as your document getts bigger, be careful about this limitation.

    Cloud Firestore is optimized for storing large collections of small documents. So you should take advantage of this feature. Even if you need to duplicate and update several documents within separate collections, I recommend you go ahead in this way.

    P.S. If you worry about costs, take also a look at Firebase realtime database and try to use them together. Are working pretty fine.

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