更新文档,如果不存在则创建
collection.doc().set()
注意:
- 此方法会覆写已有字段,需注意与
update
表现不同,比如以下示例执行set
之后follow
字段会被删除
collection.doc('doc-id').set({
name: "Hey",
count: {
fav: 1
}
}).then(function(res) {
});
// 更新前
{
"_id": "xxx",
"name": "Hello",
"count": {
"fav": 0,
"follow": 0
}
}
// 更新后
{
"_id": "xxx",
"name": "Hey",
"count": {
"fav": 1
}
}