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

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

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • Querying
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: