【发布时间】:2020-02-06 18:03:15
【问题描述】:
我正在尝试删除 Firestore 中的 2 级深度嵌套参考。我的架构如下所示:
在代码中是这样的:
{
"folder": "bla",
"title": "myTitle",
"children": [
{
"ref": "firstReference"
},
{
"ref": "secondReference"
},
{
"title": "Subcollection Title",
"children": [
{
"ref": "thirdReference"
},
{
"ref": "forthReference"
}
]
}
]
}
现在我正在寻找一种方法来从第二个子数组中删除第三个或第四个引用。
要从第一个子数组中删除一个项目,请使用以下代码:
docRef.update({children: firebase.firestore.FieldValue.arrayRemove(folder.children[index])
但此解决方案仅适用于顶层;(
有人知道如何删除更深的嵌套元素吗?
我试过了:
docRef.update({[`children[${index}].children`]: firebase.firestore.FieldValue.arrayRemove(
folder.children[index].children[secondIndex])});
但它会引发错误(路径不得包含“~”、“*”、“/”、“[”或“]”)
感谢您的帮助;)
【问题讨论】:
标签: javascript firebase vue.js google-cloud-firestore