Python 从firestore获取文档字段的字段类型

Python 从firestore获取文档字段的字段类型,python,google-cloud-firestore,Python,Google Cloud Firestore,是否可以获取文档中某个字段的字段类型 我想创建一个如下所示的函数: def print_field_types(collection_ref, document_ref): db = some_function_that_initializes_app() document = db.collection(collection_ref).document(document_ref).get().to_dict() for field in document: pr

是否可以获取文档中某个字段的字段类型

我想创建一个如下所示的函数:

def print_field_types(collection_ref, document_ref):
   db = some_function_that_initializes_app()
   document = db.collection(collection_ref).document(document_ref).get().to_dict()
   for field in document:
       print(f"Field_name : {field}, Field_type : {field.type}")
Field_name : Username, Field_type : string
Field_name : Age, Field_type : number
Field_name : Tasks, Field_type : array
其中field.type返回字段的类型。例如,它应该返回如下内容:

def print_field_types(collection_ref, document_ref):
   db = some_function_that_initializes_app()
   document = db.collection(collection_ref).document(document_ref).get().to_dict()
   for field in document:
       print(f"Field_name : {field}, Field_type : {field.type}")
Field_name : Username, Field_type : string
Field_name : Age, Field_type : number
Field_name : Tasks, Field_type : array

从文档快照中,使用
document.get
可以将字段值作为对象获取,然后在Python中,可以使用
type()
函数从该对象获取类型