我是 python 和 firestore 的新手。但我对 Firebase 有一些经验。我浏览Firestore python 的文档。我不知道如何确定任务是否成功完成或完成时出现一些错误。通常其他语言都有完成 block 。
例如,我想知道以下代码的写入是否成功或错误:
resp = doc_ref.set({
u'first': u'Alan',
u'last': u'Lovelace',
u'born': 1915
})
最佳答案
您可以查看reference对于 firestore python 客户端。它解释了操作返回的结果、可能引发的错误等。
例如,下面是 reference 的片段对于文档-
create(document_data) Create the current document in the Firestore database.
Parameters: document_data (dict) – Property names and values to use for creating a document. Returns: The write result corresponding to the committed document. A write result contains an update_time field.
Return type: google.cloud.firestore_v1beta1.types.WriteResult
Raises: Conflict – If the document already exists.
您可以使用 try except block 来捕获和处理相关情况下的错误。
和here是一篇 SO 帖子,解释了什么是 swift 完成 block 的 Python 等价物。
关于python - Firestore Python 中的完成处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49126777/