【发布时间】:2019-06-08 23:49:28
【问题描述】:
在 Firestore 中,我有一个文档,其中包含一个名为 myMap 的地图,其中包含一个名为 myArr 的数组字段。
是否可以在事务中使用arrayUnion 来更新myArr,通过向其中添加一个元素?
await admin.firestore().runTransaction(async (transaction: Transaction) => {
//
const docRef: DocumentReference = admin.firestore()
.doc(`collection/document`);
const doc: DocumentSnapshot = await transaction.get(docRef);
if (doc.exists)
await transaction.update(docRef,
{'myMap': {'myArr': FieldValue.arrayUnion('myNewValue')},}
);
});
我认为上面的代码应该添加myArr,但它会替换整个数组。
我做错了什么?
【问题讨论】:
标签: typescript firebase google-cloud-firestore