$in setting positional operator ($) in an update query

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.2.3
    • Component/s: Querying
    • None
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Consider the following example:

      db.getCollection("test").insert({
         "_id" : 5,
         "scopes" : [
             "a",
             "b"
         ],
         "tags" : [
             {
                 "name" : "abc",
                 "id" : 1
             },
             {
                 "name" : "def",
                 "id" : 2
             }
         ]
      })
       
      db.getCollection('test').update({
          "_id" : 5,
          "scopes" : { "$in" : ["a"]},
          "tags.id" : 2
      }, {
          "$set" : { "tags.$.name" : "ghi"}
      })
      

      This example changes the first tag name abc to ghi instead of the desired behavior of changing the tag with name def to ghi.

      I think the $in operator is setting the positional operator $, because if we change the query for "scopes" :

      { "$in" : ["b"]}

      , then the second tag is getting updated...

            Assignee:
            Kelsey Schubert
            Reporter:
            David Martinho
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: