我目前正在尝试使用Firestore,但卡在一个非常简单的问题上:“更新数组(也称为子文档)”。
我的数据库结构非常简单。例如:
proprietary: "John Doe",
sharedWith:
[
{who: "first@test.com", when:timestamp},
{who: "another@test.com", when:timestamp},
],
我试图将新记录推入shareWith
对象数组中,但没有成功。
我尝试过:
// With SET
firebase.firestore()
.collection('proprietary')
.doc(docID)
.set(
{ sharedWith: [{ who: "third@test.com", when: new Date() }] },
{ merge: true }
)
// With UPDATE
firebase.firestore()
.collection('proprietary')
.doc(docID)
.update({ sharedWith: [{ who: "third@test.com", when: new Date() }] })
没有一个有效,这些查询会覆盖我的数组。
答案可能很简单,但我找不到它...