|
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]}
|
|