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

Support full $slice / $sort semantics in $push

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.3
    • Affects Version/s: None
    • Component/s: Write Ops
    • None

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

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

              Created:
              Updated:
              Resolved: