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

Allow for negative $push indexes.

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.3.11
    • Fix Version/s: 3.5.6
    • Component/s: Write Ops
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Epic Link:
    • Sprint:
      Query 2017-03-27, Query 2017-04-17

      Description

      Requiring a query to determine the length of a document's array and calculate the appropriate positive integer index introduces a race condition. By allowing negative indexes (indicating distance from the end) on the $position modifier, this race condition could be avoided.

      This would match Python semantics for list manipulation. An example, given the following document:

      {
        acl: [
            {grant: True, user: "amcgregor"},
            {grant: True, user: "bdole"},
            {grant: False}
          ]
      }
      

      And the following update operation:

      {
        $push: {
          acl: {
             $each: [ { grant: True, user: "algore" } ],
             $position: -1
          }
        }
      }
      

      The resulting document should be:

      {
        acl: [
            {grant: True, user: "amcgregor"},
            {grant: True, user: "bdole"},
            {grant: True, user: "algore"},
            {grant: False}
          ]
      }
      

      The default insert location, the end (when $position is omitted or exceeds the length of the array), is unaffected.

      Thank you for your consideration!

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tess.avitabile Tess Avitabile
              Reporter:
              amcgregor Dissatisfied Former User
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              14 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: