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

array indexes and object subfields should be referenced with different syntax

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • None
    • Query Optimization

      It is currently the case that if you send an update like:

      { $set:

      { "foo.0": "x" }

      }

      You may be updating either index 0 of the array foo or the key "0" in an object. If "foo" exists as an array, then it updates index 0. If it's an object, it updates the key "0". The problem is that if "foo" doesn't yet exist, then mongo assumes you want an object.

      This has bitten us a couple times, where we've ended up with objects with numeric keys, instead of arrays.

      Ideally the syntax for these two cases would be different so there wouldn't be ambiguity. For example, array indexes could be referenced with []. It would be difficult to ever deprecate the old dot notation, but callers could switch to the square brackets and not run the risk of having this problem.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            nsanch Neil Sanchala
            Votes:
            4 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: