开发者

MongoDB update query is failing silently

I have an app using Mongoid on top of MongoDB and an update is failing silently.

The code looks like this:

# 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

No exception is thrown in this code. So I looked at my MongoDB log and constructed this query based on what mongo is trying to do:

db.users.update({ "_id": "4d5561276ce886c496000001" }, { $set: { "first_name": "Erinamodobo" } }, false);

Now this does not cause any exceptions but when I grab the record that was supposed to be updated with thi开发者_C百科s query:

db.users.find({"email":"escharling@somecompany.com"})

I see that the "first_name" attribute has not been updated.

Any idea why this could be happening? Sounds like something stupid.

Thanks!


You need to find out what

user.update_attributes!(@attributes)

is actually doing. This could be an issue with Mongoid. When you configure Mongoid, you can set up a logger. There you should be able to see what the driver is writing to MongoDB, and that should help answer your question. The next best thing is to post your code to the Mongoid mailing list (http://groups.google.com/group/mongoid) where people who work with Mongoid all the time will probably know what's going on.


Updating Mongoid to the latest rc.7 fixed this issue


Enable "safe mode" on your operations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜