node.js - Firestore set doc with merge option true or update doc

标签 node.js firebase google-cloud-firestore

我必须更新现有 Firestore 文档中的单个字段。

不过不知道使用起来有没有区别

admin.firestore().doc('doc_id').set({name:'Bill'},{ merge: true })

admin.firestore().doc('doc_id').update({name:'Bill'})

如果文档是:

{
  name: Bart,
  age: 18
}

在这种情况下,.update(...) 是否应该只更新字段而不删除字段“age”?

最佳答案

现有文档的这两个选项之间没有区别。

它们之间的区别仅在不存在的文档中很明显。 set() 如果文档不存在会创建文档,如果文档不存在 update() 会失败。

关于node.js - Firestore set doc with merge option true or update doc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60876446/

相关文章:

node.js - Nuxt - 服务器端的 Axios 请求不发送引荐来源网址

node.js - 基于 Rabbitmq key 的身份验证

android - 世博会推送通知中的警报和声音不起作用

ios - 使用 iOS Swift 进行复杂的 Firebase 查询

ios - 无法使用 firestore 数据库 swift 取消初始化

javascript - NPM 包安装到公共(public)目录中(最佳实践)

node.js - 值在 setInterval 方法 Node js 的回调内的回调中被覆盖

java - 在 firebase 动态链接中传递参数不起作用

android - SignOut 使无法保存在 firestore 中

javascript - 从 Firebase Firestore 异步返回数据