【发布时间】:2021-01-27 05:56:54
【问题描述】:
set with merge will update fields in the document or create it if it doesn't exists
update will update fields but will fail if the document doesn't exist
总是使用集合合并不是更容易吗?
价格是否略有不同?
【问题讨论】:
set with merge will update fields in the document or create it if it doesn't exists
update will update fields but will fail if the document doesn't exist
总是使用集合合并不是更容易吗?
价格是否略有不同?
【问题讨论】:
【讨论】:
不同之处在于 .set(data, {merge:true}) 如果存在则更新文档,如果不存在则创建文档。
如果文档不存在,.update() 会失败。
但为什么 .update() 仍然存在?好吧,可能是为了向后兼容。我相信带有 merge:true 的 .set() 是在 .update() 之后推出的。正如您所指出的,设置/合并更加通用。我用它代替 .update() 而不是 .add()
【讨论】: