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

Take field value from $setOnInsert when it cannot be inferred otherwise

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Query

      Take the following update:

      db.test.update(
        {"someField" : {"$all": ["a", "b"]}}, 
        {"$addToSet": {"someOtherField": 123}, 
          "$setOnInsert": {"someField": ["a", "b"]}},
        {"upsert": true})
      

      This results in the following error, because of the $all query:

      "writeError" : {
        "code" : 54,
        "errmsg" : "cannot infer query fields to set, path 'someField' is matched twice"}
      

      Given that I explicitly stated what I want the value for someField to be using $setOnInsert, it doesn't have to be a problem that the value can't be inferred from the query. It could just use value I specified as a fallback for inference, or even instead of inference.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            Targeter Sietse de Kaper
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: