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

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

    Details

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

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                8 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: