-
Type: New Feature
-
Resolution: Won't Do
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Write Ops
-
Query
When dealing with arrays with non unique values, it is impossible to remove a single value from that array in 1 update.
$pop doesn't work, because the value can be anywhere in the array.
$pull doesn't work, because that will remove all occurences of the value (which can happen in a non unique array)
$unset doesn't work, because that sets the value to NULL, instead of removing it.
EG:
> db.example.remove()
> db.example.insert({_id:1, sequence : [1,2,3,4,3,2,3,4]})
> db.example.update({_id:1}, { $unset : { 'sequence.1' : 1 }})
> db.example.find()
I'm looking for a modifier that leaves me with
{ "_id" : 1, "sequence" : [ 1, 3, 4, 3, 2, 3, 4 ] }Maybe something like
> db.example.update({_id:1}, { $remove : { 'sequence.1' : 1 }})
I'm curious what you think of it. Currently, with $addToSet and $pull it's very easy to manage arrays with unique values. For non unique arrays, there's $push to add values, but no proper way to remove values.
- is duplicated by
-
SERVER-4708 "{ $pull : { field : _value } }" support removes the first occurrences of value from field, if field is an array.
- Closed
-
SERVER-2036 $insert and $remove for arrays (currently $set, $unset, $push, and $pull are insufficient)
- Closed
- is related to
-
SERVER-1824 Support for inserting into specific array index
- Closed
-
SERVER-6399 Refactor update() code
- Closed
- related to
-
SERVER-6566 Support conditional updates: $updates
- Closed
- links to