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

Positional $ operator works unexpectedly with $and query

    XMLWordPrintableJSON

Details

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

    Description

      I have next document:

      { 
          "_id" : ObjectId("58821b8100e83a84ae110fbd"), 
          "a" : [ { "id" : 4, "group" : "a", "k" : "v1" },
                    { "id" : 4, "group" : "b", "k" : "v2" } ] 
      } 
      

      and I want to replace 'v2' by 'v_new' using $set and $and in the query:

      update({$and: [{'a.group': 'b'}, {'a.id': 4}] }, {'$set': {'a.$.k': 'v_new'} })
      

      But it replaces 'v1' by 'v_new' ($ refers to wrong element of array 'a').

      Attachments

        Activity

          People

            mark.agarunov Mark Agarunov
            chakmidlot Dima Tolkach
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: