2
刪除字段,所以想做點什麼:MongoDB的驅動紅寶石,在我triying刪除一個大文件場文檔
collection.update({'_id' => @id}, {"$unset" => {'herField'})
但這是不可能的。我不想重寫整個文檔,任何想法?
編輯:我使用https://github.com/mongodb/mongo-ruby-driver
刪除字段,所以想做點什麼:MongoDB的驅動紅寶石,在我triying刪除一個大文件場文檔
collection.update({'_id' => @id}, {"$unset" => {'herField'})
但這是不可能的。我不想重寫整個文檔,任何想法?
編輯:我使用https://github.com/mongodb/mongo-ruby-driver
你的語法看起來稍有不正確。根據文檔:
collection.update({ _id: @id }, { $unset: { herField: true } }, { multi: true });
如果要更新多個文檔,則需要'多個'選項。例如。來自這個集合的所有記錄。
http://docs.mongodb.org/manual/reference/operator/unset/#op._S_unset
我使用https://github.com/mongodb/mongo-ruby-driver。我只是編輯一個文件。 – ie8888
@ ie8888:如果你在JavaScript的意義上使用'$ unset'中的某些東西,它會起作用嗎?說'{$ unset:{herField:true}'。 –
我沒有使用JavaScript,我正在使用Ruby。當我運行我的代碼時,我得到了無效修飾符指定:$ unset(Mongo :: OperationFailure) – ie8888