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

Problems using the $[<identifier] operator in 3.6.2

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.2
    • Component/s: Querying
    • Labels:
      None
    • ALL

      Hello,

      I'm having major problems getting the new $[<identifier] operator to work as expected in mongodb v. 3.6.2.

      I have a collection containing the following type of documents:

      {
         ...,
         "documents": [
            {
               "id": "1234",
               "status": "UNTOUCHED"
            },
            ...
         ]
      }
      

      I'm executing the following update stmt:

      db.mycollection.update(
         { },
         { $set: { "documents.$[e].status" : "TOUCHED" } },
         { arrayFilters: [ { "e.id": "1234" } ] }
      )
      

      And I get the following result:

      code: 16837
      msg: cannot use the part (documents of documents.$[e].status) to traverse the element...
      

      I thought it might be my mongodb installation which was somehow corrupted so I did the following to verify that this was not the issue:

      1) Went to Mongo Atlas and create a whole new cluster with version 3.6.2 of mongodb.

      2) Create a collection, "students2", containing the following two documents:

      {
         "_id" : 1,
         "grades" : [
            { "grade" : 80, "mean" : 75, "std" : 6 },
            { "grade" : 85, "mean" : 90, "std" : 4 },
            { "grade" : 85, "mean" : 85, "std" : 6 }
         ]
      }
      {
         "_id" : 2,
         "grades" : [
            { "grade" : 90, "mean" : 75, "std" : 6 },
            { "grade" : 87, "mean" : 90, "std" : 3 },
            { "grade" : 85, "mean" : 85, "std" : 4 }
         ]
      }
      

      3) Executed the following command:

      db.students2.update(
         { },
         { $set: { "grades.$[elem].mean" : 100 } },
         {
           multi: true,
           arrayFilters: [ { "elem.grade": { $gte: 85 } } ]
         }
      )
      

      This resulted in a new error:

      code: 2
      msg: No array filter found for identifier 'elem' in path 'grades.$[elem].mean'
      

      Pease note that the above have been taking directly from https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/#update-all-documents-that-match-arrayfilters-in-an-array without modifying it the slightest.

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            mlarsson Morten L
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: