[EDIT: Thanks to @JRLtechwriting, the Storage Size Calculations doc mentioned below has been updated so it no longer mentions namespaces-- Firestore does not (yet?) support them-- and includes more complete examples. After these improvements, my question may not come up again!]
I'm trying to write a general function to calculate the storage size of a Cloud Firestore document, but I'm already stuck on calculating the size of the document's name because I don't know exactly what they mean by a document's "namespace" in the Storage Size Calculations guide:
The size of a document name is the sum of:
- The namespace string size (if not in the default namespace)
- The full string size of the document name (integer IDs are 8 bytes each)
- 16 additional bytes
It also says that the namespace is stored as a string. So, for this hypothetical CFS doc...
var alovelaceDocumentRef = db.collection('users').doc('alovelace');
...which, per the Cloud Firestore Data Model docs, can also be referenced like this...
var alovelaceDocumentRef = db.doc('users/alovelace');
...would the namespace string be 'users'
? Or maybe 'users/'
? Unfortunately, all of the examples in the Storage Size Calculations guide assume the default namespace (for which the size is 0).
I feel like I should be able to experimentally find the answer to my question, but the only way I can think of to do so is to:
- Create a document in a non-default namespace
- Track its size in a variable "docSize" using the information in the Storage Size Calculations guide) as I incrementally add data to it
- When I get an error message that I have exceeded the maximum document size (1,048,576 bytes, according to the Quotas and Limits guide), subtract docSize from 1,048,576 to get the size of the namespace string
But this approach seems labor-intensive, and probably prone to inaccuracies arising from other limitations of my understanding/knowledge, so I'm hoping one of you more-knowledgeable folks can help. Thanks!