繁体   English   中英

无法在 firebase/firestore 的数组中删除具有特定值的 object

[英]Can't delete an object with a certained value inside an array in firebase/firestore

所以我正在建立一个会员系统,每个会员都有一个数组积分。 但是当有人试图删除这一点时,我似乎无法删除 object。

users(collection) -
 member(document) -
      "id" . --fields
      "username" . --fields
      "userevents" . --array
         [0]
            "id"
            "date"
            "price"
         [1]
            "id"
            "date"
            "price"




deletePoint = (userId, pointId, date, price) => {
    let docRef = this.db.collection('users').doc(userId);
    docRef.update({
      points: this.db.FieldValue.arrayRemove({
        date: date,
        id: pointId,
        price: price,
      }),
    });
  };

this.db 是 firebase.firestore()

根据使用 arrayRemove 时的文档,您必须直接指向要删除的字段,而不是所述字段中的内容,因此您的示例将变为:

deletePoint = (userId, pointId, date, price) => {
    let docRef = this.db.collection('users').doc(userId);
    docRef.update({
      points: this.db.FieldValue.arrayRemove("0"),
    });
  };

这将删除索引为 0 的字段(id、日期、价格)的全部内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM