【问题标题】:Delete a field in a Firestore doc from a cloud function从云函数中删除 Firestore 文档中的字段
【发布时间】:2019-01-23 14:42:09
【问题描述】:

如何从云存储功能中删除文档中的字段?

我正在使用事务,所以我尝试了这种方法:

    const { FieldValue } = require('@google-cloud/firestore');
    ...   
    ..
    transaction.update(docRef, { fieldToRemove: FieldValue.delete() });

但我收到此错误:

Transaction failure: Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Argument "dataOrField" is not a valid Document. Couldn't serialize object of type "DeleteTransform". Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the 'new' operator).

谢谢!

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    您可以按照the docs 使用FieldValue.delete(),但需要从“firebase-admin”导入它:

    const admin = require('firebase-admin');
    const FieldValue = admin.firestore.FieldValue;
    transaction.update(docRef, { fieldToRemove: FieldValue.delete() });
    

    【讨论】:

      猜你喜欢
      • 2020-10-25
      • 2020-09-11
      • 1970-01-01
      • 2018-04-09
      • 1970-01-01
      • 2020-10-31
      • 2019-11-25
      • 1970-01-01
      • 2020-09-01
      相关资源
      最近更新 更多