You can now limit the resulting elements in the array after you push. The new syntax is :
db.coll.update({...}, {$push: { $each:[<values>], $slice:-N, $sort:{...}}}
The initial implementation (see SERVER-8069 for more) only supports negative slice (taking stuff from the end of the array).
Sorting is by embedded document fields and doesn't work any type which is not an embedded docs (in the array).
- depends on
-
SERVER-6399 Refactor update() code
- Closed
- is related to
-
SERVER-8008 $push to sorted array
- Closed
-
SERVER-1050 not allowed to $push and $pop to same field in same update
- Closed
-
SERVER-2363 $push/$pushAll support for insertion at any position (top/bottom/ordinal)
- Closed
- related to
-
CSHARP-684 Add new features to Update builder for server 2.4
- Closed
-
SERVER-8069 Support full $slice / $sort semantics in $push
- Closed
-
SERVER-8746 $push w/ $sort: make $slice optional
- Closed