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

$push/$pushAll support for insertion at any position (top/bottom/ordinal)

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.3
    • Affects Version/s: None
    • Component/s: Write Ops
    • Labels:
      None

      Add $position option which takes a positive number.

      db.col.save({_id:1, a: [3]})
      db.col.update({}, {$push: {a: {$each:[1,2], $position:0 }}}) // pushes to front of array
      

      If $position is equal to or greater than the array size then it will be ignored and is effectively a push to the end, which is the default behavior if not specified.

      This will allow you to effectively $pop from the top and add to the bottom or vice versa using $slice since you push in either direction.

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            scotthernandez Scott Hernandez (Inactive)
            Votes:
            8 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: