Reputation: 107
Usually to remove some fields from collections in MongoDB, $unset
is used. What can I do in Ruby to accomplish that? I have tried to read this, but I couldn't understand how to use it. I am new to Ruby and still learning to work with it.
Upvotes: 1
Views: 351
Reputation: 42779
The $unset
operator is used through the update
command which is documented here for the ruby driver.
Taking a step back, the standard (10gen-maintained) MongoDB Ruby driver can do absolutely everything that mongodb can. It exposes very literally the full capabilities of mongodb, just like the mongodb drivers in other languages do. So don't worry about being able to do mongo things in any particular language.
You might be wondering about the capabilities of popular ODM layers since they vary. ODM layers map mongodb documents to native language objects. In Ruby, mongoid is the most popular ODM. As @Tilo points out, it also supports explicitly removing fields from documents through its higher-level API.
Upvotes: 2
Reputation: 33752
Please check this issue for Mongoid:
https://github.com/mongoid/mongoid/pull/635
p = Product.first
p.raw_attributes.delete :foo
p.save
Upvotes: 0