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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 3.2.3
    • Querying
    • None
    • ALL

    Description

      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...

      Attachments

        Activity

          People

            kelsey.schubert@mongodb.com Kelsey Schubert
            davidmartinho David Martinho
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: