使用无效数据调用函数FieldValue.arrayUnion()。 FieldValue.serverTimestamp()只能与update()和set()一起使用 [英] Function FieldValue.arrayUnion() called with invalid data. FieldValue.serverTimestamp() can only be used with update() and set()

查看:101
本文介绍了使用无效数据调用函数FieldValue.arrayUnion()。 FieldValue.serverTimestamp()只能与update()和set()一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

addDeposit(account, deposit) {

    let depositsDoc = this.db.collection("accounts")
                      .doc(account.id)
                      .collection("deposits")
                      .doc("deposits");

    return new Promise((resolve, reject) => {

      deposit.created_at = firebase.firestore.FieldValue.serverTimestamp();

      depositsDoc.update({
        "deposits": firebase.firestore.FieldValue.arrayUnion(deposit)
      })
        .then((a) => {
           resolve('success');
        })
        .catch((error) => {
          reject("failed");
        });

    })
      .then((res) => {
        return res;
      })
      .catch((error) => {
        return error;
      })

    }

**带角度的Firestore(使用默认的Firebase SDK而不是angularfire)**

**Firestore with angular (Using default firebase SDK not angularfire ) **

我试图通过直接添加 created_at将时间戳添加到存款对象属性调用时间戳。通过这样做,我得到上面标题中的错误。
如何在Firestore中的对象数组中的对象上添加时间戳?

I was trying to add timestamp to the deposit object by directly adding a "created_at" property calling the timestamp. By doing this, I am getting the error titled above. How can I add timestamp to a object in an array of objects in firestore?

推荐答案

您不能使用 FieldValue.serverTimestamp()作为要对文档字段的数组类型值进行联合(添加)或从其中删除的值。如果要使用该时间戳记值,则需要将其直接传递到要更新或设置的字段。

You can't use FieldValue.serverTimestamp() as the value to union (add) or remove, to or from, an array type value of a document field. If you want to use that timestamp value, you need to pass it directly to a field you're updating or setting.

您必须考虑另一种方法构建满足您的需求并满足Firestore要求的数据。

You'll have to think of another way you structure your data that meets your needs and also satisfies Firestore requirements.

这篇关于使用无效数据调用函数FieldValue.arrayUnion()。 FieldValue.serverTimestamp()只能与update()和set()一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆