【发布时间】:2020-08-31 23:39:32
【问题描述】:
我想从 Firestore 中的数组中删除一个值。我正在使用 firebase 功能,并在删除用户后更新此字段。我尝试过更新数组,尝试过 arrayRemove 以及其他各种行。因为每次我想运行测试时都必须进行部署,所以每次都很难构建和删除数据。
所以我希望有人可以帮助我找到here:
我想遍历一个 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 未定义
【问题讨论】:
标签: javascript firebase google-cloud-firestore firebase-admin