根据官方文档[1],App Engine 的“Cloud Firestore 存储数据”配额只包括实际数据(document fields)的大小,不包括开销数据。因此,如果您的文档包含了索引、元数据等开销数据,那么这些开销数据的大小将不会计入配额。
以下是一个 python 的代码示例,用于计算 Firestore 文档的大小:
from google.cloud import firestore
db = firestore.Client()
doc_ref = db.collection(u'mycollection').document(u'mydoc')
doc = {
u'string_value': u'123456789abcdef',
u'number_value': 42,
u'boolean_value': True,
u'timestamp_value': firestore.SERVER_TIMESTAMP,
}
doc_ref.set(doc)
# Get the size of the document
doc_size = doc_ref.get().to_dict().__sizeof__()
print("Document size: {} bytes".format(doc_size))
在上述示例中,to_dict().__sizeof__()
方法返回 Firestore 文档的大小(以字节为单位)。请注意,这个大小只计算文档实际数据的大小,不包括开销数据。如果您的文档中包含了开销数据,您需要手动计算其大小并将其包含在配额之外。
参考资料: [1] Cloud Firestore Quotas and limits: https://cloud.google.com/firestore/quotas