Firebase 删除数组项

Firebase Remove An Array Item

我想从 Firestore 中的数组中删除一个值。我正在使用 firebase 函数并在删除用户后更新此字段。我试过更新数组,我试过 arrayRemove 和各种其他行。因为每次我想 运行 测试都必须部署,所以它越来越耗时,而且每次都很难构建和删除数据。

所以我希望有人可以帮助我找到这个解决方案 :

我想遍历 ID 列表(数据库中的用户)并提取他们的匹配项,然后从他们的匹配项列表中删除特定 ID。

当我运行这个的时候,它不知道firebase.firestore是什么。所以我不确定如何使用这种类型的 FieldValue.delete() 注册 firestore。本节的目标是什么? “admin.FieldValue.delete()”?

admin.firestore()
.collection("Users")
.doc(matches[i])
.update({
  [userId]: firebase.firestore.FieldValue.delete(),
});

我也试过这个:

admin
.firestore()
.collection("Users")
.doc(matches[i])
.update({
  matches: admin.firebase.firestore.FieldValue.arrayRemove(userId),
});

但它又不知道 firebase.firestore 是什么。从数组中删除一个值的正确方法是什么?

此外,我担心在 for 循环中进行标注,但我没有找到解决方法。有没有人有什么建议?这些不需要是异步的,因为所有事务都不相互依赖。

我在 firebase 函数中收到的错误消息:

ReferenceError: firebase is not defined

如果您像这样导入 Admin SDK:

const admin = require("firebase-admin");

您将要使用 admin.firestore.FieldValue.delete()arrayRemove().

的相同模式