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总是使用集合合并不是更容易吗?
价格略有不同吗?
发布于 2021-01-27 13:54:59
发布于 2021-01-28 07:58:00
不同之处在于,.set(data,{merge:true})将更新文档(如果文档存在,则为),如果文档没有,则创建文档。
如果文档不存在,.update()将失败。
但是为什么.update()仍然存在?可能是为了向后兼容性。我相信使用merge:true的.set()是在比.update()晚的时候引入的。正如您已经指出的,set/merge更通用。我使用它来代替.update()和.add()
https://stackoverflow.com/questions/65913605
复制相似问题