Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以将 MongoDB 的 save() 命令与“$set”之类的更新运算符一起使用吗?
或者 save() 可以用来“更新” - 仅在替换所有字段(ID除外)时?
你不能。
$set是update语句的运算符。Save 是一种语法糖,它将插入文档或用整个新文档覆盖现有文档。
$set
update
您可能正在寻找选项设置为 true的update操作,并且可能还有操作符。upsert$set$setOnInsert
upsert
$setOnInsert