Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8008

$push to sorted array

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor - P4
    • Resolution: Done
    • None
    • 2.3.2
    • Write Ops
    • None

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              alerner Alberto Lerner
              yfinkelstein Yuri Finkelstein
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: