[SERVER-32140] $[<identifier>] does not work in 3.6.0-rc8 with FCV=3.4 Created: 01/Dec/17  Updated: 27/Oct/23  Resolved: 01/Dec/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.6.0-rc8
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bashar Mahasen Assignee: Tess Avitabile (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac 10.12.6


Operating System: ALL
Steps To Reproduce:

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 ] } ]})"
	}
})
> 

Participants:

 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 ()"



 Comments   
Comment by Kelsey Schubert [ 01/Dec/17 ]

Thanks for confirming the issue has been resolved!

Comment by Bashar Mahasen [ 01/Dec/17 ]

setting db.adminCommand(

{ setFeatureCompatibilityVersion: "3.6" }

) fixed the issue.

Issue resolved.

Comment by Tess Avitabile (Inactive) [ 01/Dec/17 ]

Hi bashar.mahasen@gmail.com.

It looks like you need to set the featureCompatibilityVersion of the server to 3.6 and upgrade your mongo shell to 3.6. The arrayFilters feature is only available when the featureCompatibilityVersion of the server is 3.6, and the older version of the mongo shell will not pass arrayFilters through to the server.

Best,
Tess

Generated at Thu Feb 08 04:29:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.