Now that SERVER-991 is resolved, more can be accomplished with this if Mongo would maintain arrays sorted by specified field.
Let's say the initial document state was:
{a: [{version: 1, data: 10}]}
After
{ $push : { a : { $each : [ { version : 3, data : 6 } ] , $orderBy : {version : -1 }, $trimTo : 11 } } }
it will be
{a: [{version: 2, data: 6}, {version: 1, data: 10}]}
After
{ $push : { a : { $each : [ { version : 2, data : 8 } ] , $orderBy : {version : -1 }, $trimTo : 11 } } }
it will be
{a: [{version: 3, data: 6}, {version: 2, data: 8}, {version: 1, data: 10}]}
In this case,
Mongo maintains array in "a" sorted by version in discending order and
trims the array to 11 elements by dropping the very last element when
required.
The context here is that this mechanism would enable capability similar to
http://hbase.apache.org/book/versions.html
- related to
-
SERVER-991 $push with $slice + $sort
- Closed
-
CSHARP-684 Add new features to Update builder for server 2.4
- Closed