MongoDB更新查询正在无声地失败
我有一个在MongoDB上使用Mongoid的应用程序,更新失败了 代码如下所示:MongoDB更新查询正在无声地失败,mongodb,mongoid,Mongodb,Mongoid,我有一个在MongoDB上使用Mongoid的应用程序,更新失败了 代码如下所示: # Are we getting a new attribute? Yes we are! p "attr first name = #{@attributes['first_name']}" if user.update_attributes!(@attributes) u = User.find(params[:id]).to_json end 此代码中没有引发异常。因此,我查看了我的MongoDB
# Are we getting a new attribute? Yes we are!
p "attr first name = #{@attributes['first_name']}"
if user.update_attributes!(@attributes)
u = User.find(params[:id]).to_json
end
此代码中没有引发异常。因此,我查看了我的MongoDB日志,并根据mongo的尝试构建了这个查询:
db.users.update({ "_id": "4d5561276ce886c496000001" }, { $set: { "first_name": "Erinamodobo" } }, false);
现在这不会导致任何异常,但当我抓取本应使用此查询更新的记录时:
db.users.find({"email":"escharling@somecompany.com"})
我看到“first_name”属性尚未更新
知道为什么会这样吗?听起来很愚蠢
谢谢 在您的操作中启用“安全模式”。您需要了解什么是安全模式
user.update_attributes!(@attributes)
他实际上在做什么。这可能是Mongoid的一个问题。配置Mongoid时,可以设置记录器。在那里,您应该能够看到驱动程序正在向MongoDB写入什么,这将有助于回答您的问题。下一个最好的方法是将代码发布到Mongoid邮件列表中(http://groups.google.com/group/mongoid)一直使用Mongoid的人可能知道发生了什么。将Mongoid更新到最新的rc。7修复了这个问题。我不知道到底是谁否决了这个问题,但我正在投票支持它。这是你可以采取的唯一第一步。安全模式要求mongodb服务器在等待时返回状态并阻塞。这确保了在mongo有机会更新之前,您不会获取该值。