【发布时间】:2020-11-22 06:19:33
【问题描述】:
我想使用 Firestore 函数更新地图中的一个数组。我的数据结构如下所示:
在这种情况下,我想更新 {uid} 映射中的 shareRecordsWith 数组。
我一直在尝试使用以下 Firestore 功能,但它不起作用。
const recordsDict = {"uid": aboutUID, "accessType": accessType}
profilesRef.doc(uid).set({
[uid]: {
{'shareRecordsWith': admin.firestore.FieldValue.arrayUnion(recordsDict)},
{merge: true}
}
});
有没有办法通过 Firestore 函数更新地图中的数组?
编辑:根据建议,我将功能更改为
profilesRef.doc(uid).set({
[`${uid}.shareRecordsWith`]: admin.firestore.FieldValue.arrayUnion(recordsDict)
}, { merge: true })
不幸的是,它在文档中添加 ${uid}.shareRecordsWith 作为新字段,而不是添加到 {uid} 映射中的 shareRecordsWith 数组中。
这就是它的样子:
【问题讨论】:
标签: javascript firebase google-cloud-firestore google-cloud-functions