python - Firestore Python 中的完成处理

标签 python flask google-cloud-firestore

我是 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/

相关文章:

javascript - 如何在firebase云函数中添加时间戳

python - 解释 __dict__ 属性

python - pandas dataframe 按 nan 数删除列

python - Flask 应用程序崩溃“正在使用重新加载程序重新启动....socket.error : [Errno 98] Address already in use

javascript - 休息API : user-agent-based client (app) authorization

firebase - 如何按类别显示产品 flutter Firestore

python - 情感分析/线性回归(Django)

python - 将txt文件的全文存储到mongodb中

algorithm - Delta E (CIE Lab) 在 SQL 中计算和排序的性能

javascript - 向创建的对象添加属性(Firebase 函数)