SERVER-8008 and SERVER-991 introduce the clause $slice to the $push update mod. The clause now only supports negative slices (trimming from the back of the array). The full $slice semantics support trimming from the front and also skipping (moved to issue SERVER10988). We'd like to support all these features here.
In terms of $sort, we'd like to use query semantics for that clause. For example,
doc = { x: [ {a: [{b:1},{b:3}], a: [{b:2},{b:0}] } ] } $sort: {'a.b':1} would reorder the two 'a' elements.
This allows slicing from the front or back of the array:
> db.a.save({_id:1, a: [1,2,3]}) // Top slice > db.a.update({}, {$push: {a: {$each : [4], $slice: 2}}}) > db.a.find() {_id:1, a:[1,2]} // Bottom slice > db.a.update({}, {$push: {a: {$each : [4], $slice: -2}}}) > db.a.find() {_id:1, a:[2,4]}
- depends on
-
SERVER-6399 Refactor update() code
- Closed
- is duplicated by
-
SERVER-8746 $push w/ $sort: make $slice optional
- Closed
- is related to
-
SERVER-991 $push with $slice + $sort
- Closed
-
SERVER-10988 Support $slice from middle for $push
- Closed
-
SERVER-9590 Update $push + $sort should be able to sort by the whole array element
- Closed
- related to
-
SERVER-8746 $push w/ $sort: make $slice optional
- Closed