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

Allow Field Name Duplication with Modifiers

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • Labels:
      None
    • Query

      Currently, if a field is referenced twice within two different modifiers, Mongo errors out, even if their is actually conflict. In other words, the error check is dumb. It's understandable why this was done, but I think this behavior deserves further consideration as Mongo matures. Take the following example:

      {$set :

      {age: 20}

      , $inc : {age: 2}}

      Running this as part of an update will generate a "Field name duplication not allowed with modifiers" error. Any human reading this however can easily determine the intention, and that such an operation could have succeeded without error. The result of which should have been setting the field "age" to the value 22.

      A relatively easy first step solution here, would be to allow name duplication between the $set modifiers and the other modifiers. The rule should be that the $set modifier operation should always happen first, followed by the rest of the modifiers, in order. In other words, any other modifier operations should be applied to the result of $set.

      Of course I'm unaware of how easy or difficult this would be to implement in Mongo, given it's atomic nature and all, but it's worth considering whether implementing this is possible or not.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            wardrop Tom Wardrop
            Votes:
            24 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated:
              Resolved: