MongoDB driver ruby, remove field in document

1.2k views Asked by At

I am triying remove field in a big document, therefore I would like to do something:

collection.update({'_id' => @id},  {"$unset" => {'herField'})

But it is not possible. I don't want to rewrite entire document, any idea?

EDIT: I am using https://github.com/mongodb/mongo-ruby-driver

1

There are 1 answers

5
mbaird On BEST ANSWER

Your syntax looks slightly incorrect. As per docs:

collection.update( { _id: @id }, { $unset: { herField: true } }, { multi: true });

Need the 'multi' option if you want to update multiple documents. E.g. from all records on this collection.

http://docs.mongodb.org/manual/reference/operator/unset/#op._S_unset