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

$[<identifier>] does not work in 3.6.0-rc8 with FCV=3.4

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • 3.6.0-rc8
    • Querying
    • None
    • Mac 10.12.6
    • ALL
    • Hide

      db.collection.update(    { myArray: [ "0", "1" ] },    { $set: { "myArray.$[element]": "2" } },    { arrayFilters: [ { element: "0" } ],      upsert: true } )
      WriteResult({
      	"nMatched" : 0,
      	"nUpserted" : 0,
      	"nModified" : 0,
      	"writeError" : {
      		"code" : 16836,
      		"errmsg" : "cannot use the part (myArray of myArray.$[element]) to traverse the element ({myArray: [ \"0\", \"1\" ]})"
      	}
      })
      

      Another example from docs
      https://docs.mongodb.com/master/reference/operator/update/positional-filtered/#up._S_[<identifier>]

      > db.students3.insert([
      ...    { "_id" : 1,
      ...       "grades" : [
      ...         { type: "quiz", questions: [ 10, 8, 5 ] },
      ...         { type: "quiz", questions: [ 8, 9, 6 ] },
      ...         { type: "hw", questions: [ 5, 4, 3 ] },
      ...         { type: "exam", questions: [ 25, 10, 23, 0 ] },
      ...       ]
      ...    }
      ... ])
      BulkWriteResult({
      	"writeErrors" : [ ],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 1,
      	"nUpserted" : 0,
      	"nMatched" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      > 
      > 
      > 
      > db.students3.update(
       {},
          { $inc: { "grades.$[].questions.$[score]": 2 } },
          { arrayFilters: [  { "score": { $gte: 8 } } ], multi: true}
       )
      WriteResult({
      	"nMatched" : 0,
      	"nUpserted" : 0,
      	"nModified" : 0,
      	"writeError" : {
      		"code" : 16837,
      		"errmsg" : "cannot use the part (grades of grades.$[].questions.$[score]) to traverse the element ({grades: [ { type: \"quiz\", questions: [ 10.0, 8.0, 5.0 ] }, { type: \"quiz\", questions: [ 8.0, 9.0, 6.0 ] }, { type: \"hw\", questions: [ 5.0, 4.0, 3.0 ] }, { type: \"exam\", questions: [ 25.0, 10.0, 23.0, 0.0 ] } ]})"
      	}
      })
      > 
      

      Show
      db.collection.update( { myArray: [ "0" , "1" ] }, { $set: { "myArray.$[element]" : "2" } }, { arrayFilters: [ { element: "0" } ], upsert: true } ) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 16836, "errmsg" : "cannot use the part (myArray of myArray.$[element]) to traverse the element ({myArray: [ \"0\", \"1\" ]})" } }) Another example from docs https://docs.mongodb.com/master/reference/operator/update/positional-filtered/#up._S_[ <identifier>] > db.students3.insert([ ... { "_id" : 1, ... "grades" : [ ... { type: "quiz" , questions: [ 10, 8, 5 ] }, ... { type: "quiz" , questions: [ 8, 9, 6 ] }, ... { type: "hw" , questions: [ 5, 4, 3 ] }, ... { type: "exam" , questions: [ 25, 10, 23, 0 ] }, ... ] ... } ... ]) BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 1, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] }) > > > > db.students3.update( {}, { $inc: { "grades.$[].questions.$[score]" : 2 } }, { arrayFilters: [ { "score" : { $gte: 8 } } ], multi: true } ) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 16837, "errmsg" : "cannot use the part (grades of grades.$[].questions.$[score]) to traverse the element ({grades: [ { type: \"quiz\", questions: [ 10.0, 8.0, 5.0 ] }, { type: \"quiz\", questions: [ 8.0, 9.0, 6.0 ] }, { type: \"hw\", questions: [ 5.0, 4.0, 3.0 ] }, { type: \"exam\", questions: [ 25.0, 10.0, 23.0, 0.0 ] } ]})" } }) >

    Description

      original summary

      $[<identifier>] is not working in 3.6.0-rc8

      original description

      $[<identifier>] isn't working and the error code is always 16836 "cannot use the part () to traverse the element ()"

      Attachments

        Activity

          People

            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            bashar.mahasen@gmail.com Bashar Mahasen
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: