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

Support full $slice / $sort semantics in $push

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.3
    • Component/s: Write Ops
    • Labels:
      None

      Description

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              scotthernandez Scott Hernandez
              Reporter:
              alerner Alberto Lerner
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: