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

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 2.5.3
    • None
    • Write Ops
    • 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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: