MongoDB驱动程序ruby,删除文件中的字段

时间:2013-08-30 16:29:50

标签: ruby mongodb-ruby

我正在一个大文档中删除字段,因此我想做点什么:

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

但这是不可能的。我不想重写整个文档,任何想法?

编辑:我正在使用https://github.com/mongodb/mongo-ruby-driver

1 个答案:

答案 0 :(得分:2)

您的语法看起来有些不正确。根据文档:

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

如果要更新多个文档,需要“多个”选项。例如。来自该系列的所有记录。

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