我目前正在更新一个Rails应用程序到Mongoid5。我在更新一些使用过时方法(find_and_modify)的代码时遇到了问题。任何帮助都将不胜感激。
在Mongoid 4中,我有这个方法来查找和更新:
LineItem.where({
date: Date.today,
location: "Location",
department: "Department"
}).find_and_modify({
"$set" => {
hours: 8,
updated_at: Time.current
},
"$setOnInsert" => {
account_id: ObjectId("5739f4534f4e48b2aa00091c"),
date: Date.today,
location: "Location",
department: "Department",
created_at: Time.current
}
}, upsert: true)使用Mongoid 5的等价物是什么?
谢谢。
发布于 2016-12-05 18:52:37
从this changelog:
find_and_modify已被移除,取而代之的是3个选项:find_one_and_update、find_one_and_delete和find_one_and_replace。
https://stackoverflow.com/questions/37263680
复制相似问题