cannot use the part (…) to traverse the element

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



cannot use the part (…) to traverse the element



Running mongod 3.6 and attempting to use this example.


mongod



Here is the sample data:


> db.students2.find().pretty()

"_id" : 1,
"grades" : [

"grade" : 80,
"mean" : 75,
"std" : 8
,

"grade" : 85,
"mean" : 90,
"std" : 6
,

"grade" : 85,
"mean" : 85,
"std" : 8

]


"_id" : 2,
"grades" : [

"grade" : 90,
"mean" : 75,
"std" : 8
,

"grade" : 87,
"mean" : 90,
"std" : 5
,

"grade" : 85,
"mean" : 85,
"std" : 6

]



I am attempting to use the all positional operator as specified in the example:


> db.students2.update(, $inc: "grades.$.std" : -2 , multi: true)
WriteResult(
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" :
"code" : 16837,
"errmsg" : "cannot use the part (grades of grades.$.std) to traverse the element (grades: [ grade: 80.0, mean: 75.0, std: 8.0 , grade: 85.0, mean: 90.0, std: 6.0 , grade: 85.0, mean: 85.0, std: 8.0 ])"

)



Why is this error message occurring? Am I not following the documentation properly?





Run this command in mongo shell db.adminCommand( setFeatureCompatibilityVersion: "3.6" )
– Anthony Winzlet
Aug 10 at 8:58


db.adminCommand( setFeatureCompatibilityVersion: "3.6" )





@AnthonyWinzlet Hey, this worked! Would love it if you could provide an answer to this question as well as elaborate a little bit on how to fix this issue if using a MongoDB driver (such as the official one or mongoose).
– Bennett
Aug 11 at 23:03


mongoose




1 Answer
1



When switching from lower version to higher version for mongodb you have to set setFeatureCompatibilityVersion for your mongodb which


setFeatureCompatibilityVersion



Enables or disables the features that persist data incompatible with
earlier versions of MongoDB. You can only issue the
setFeatureCompatibilityVersion against the admin database.



You can simply set this by running this command in mongo shell


db.adminCommand( setFeatureCompatibilityVersion: "3.6" )






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS