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

Sort order of array indexes can determine success of an update

    • Query
    • ALL
    • 0

      A quirk of the update language is that when there are multiple updates that reference indexes in the same array, the updates are ordered by the lexicographic order of the indexes, rather than numerical order. For example, when updating indexes 2 and 10 the update to 10 applies first.

      We noted this behavior in SERVER-31821, but we did not realize at the time that there are updates that would succeed if applied in ascending numerical order but fail because they are applied in lexicographic order.

      Consider the update:
      {$inc: {"array.2": 1, "array.10": 1}}

      If "array" is initially empty, the update applies to "array.10" first, which creates an entry at slot 10 and extends the array with "null" for slots 0-9. The update for "array.2" then gets applied to a null value, causing it to fail. If these updates had been applied in the opposite order (numerically ascending), both would have succeeded.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            justin.seyster@mongodb.com Justin Seyster
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: