gpt4 book ai didi

mongodb - 为什么 MongoDB 不再允许对空文档使用 $set 和 $unset?

转载 作者:可可西里 更新时间:2023-11-01 10:04:13 28 4
gpt4 key购买 nike

我刚刚从 MongoDB 2.2 版更新到 2.6 版,发现您不能再在 update 中使用 $set$unset 运算符> 使用空字典的方法。例如,调用 db.mytable.update({field:value}, {$set:{}}) 过去只保留文档不变,但现在它会引发错误,说明值$set 不能为空。

有人可以证明为什么这是对旧行为的改进吗?对我来说,它只会产生对额外逻辑的不必要需求,例如 if 语句,以确保在尝试 update 之前值不为空。

最佳答案

SERVER-12266包含官方解释。特别是这个 comment :

I spoke to Scott Hernandez about this today, and he explained the new strictness around empty modifiers is intended to alert users that were inadvertently sending over empty updates. [...]

这是否合理,我不能说。我想您可以通过默认将 _id(或另一个常量字段)附加到 $set 值来解决这个问题。

关于mongodb - 为什么 MongoDB 不再允许对空文档使用 $set 和 $unset?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24814326/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com