小编pac*_*ity的帖子

更新Firestore中对象中的字段?

这是文档中提供的用于更新firebase中嵌套对象中的字段的示例.

var frankDocRef = db.collection("users").doc("frank");
frankDocRef.set({
name: "Frank",
favorites: { food: "Pizza", color: "Blue", subject: "recess" },
age: 12
});

// To update age and favorite color:
db.collection("users").doc("frank").update({
"age": 13,
"favorites.color": "Red"
})
.then(function() {
console.log("Document successfully updated!");
});
Run Code Online (Sandbox Code Playgroud)

而不是更新收藏夹,我想添加到收藏夹,有人会指出我正确的方向如何做到这一点.

让我们说我想

firebase: "Help"
the the resulting favourites object should be
favorites: { food: "Pizza", color: "Blue", subject: "recess", firebase: "Help" },
Run Code Online (Sandbox Code Playgroud)

我使用set操作但是它会覆盖所有内容.

javascript firebase google-cloud-firestore

8
推荐指数
1
解决办法
8622
查看次数