Laszlo Hornyak
unread,Jul 22, 2013, 5:43:51 AM7/22/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongod...@googlegroups.com
Hi,
In a data processing application I would like to remove several fields fields from a document and replace it with a new field. The $unset operator works fine for a single field. e.g.
> db.t.insert({"_id" : 1, a : 1, b : 2, c : 3, d : 4});
> db.t.insert({"_id" : 3, a : 1, b : 2, c : 3, d : 4});
> db.t.update({_id : 3}, {$unset : {a : 1} });
> db.t.find();
{ "_id" : 3, "b" : 2, "c" : 3, "d" : 4 }
I gave it a try but $unset does not support arrays and you can not set multiple $unset in the update document since the second just overwrites the first in memory, so if I try that, one of the fields get deleted while the other remains in the document.
Therefore
- I have to send an update to the document for each $unset
- or I have to replace the whole document
- etc?
Which of these is recommended? Is there any plan to implement something like an $unsetall?
I could imagine it like this
> db.t.update({_id : 3}, {$unsetall : ['a','b','c'] });
Thank you,
Laszlo