这是在 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!");
});
我想不是更新收藏夹,而是将内容添加到收藏夹中,请问有没有人能指导我如何实现。
假设我想要...
firebase: "Help"
the the resulting favourites object should be
favorites: { food: "Pizza", color: "Blue", subject: "recess", firebase: "Help" },
我使用点操作符和set()方法,但它会覆盖所有东西。
templateStrings
。首先声明一个空对象const update = {};
,然后按如下方式设置你想要更新的字段update[\
favorites.${someUid}`] = 'abc';,最后更新集合
db.collection("users").doc("frank").update(update)`。 - Visperceptlet update_id = { department:{ } }
的情况,现在我想在 department 对象中添加新的数据。如何更新 department 映射而不获取先前的值? - Balaji Sivasakthi