无法使用零件(...)遍历元素 [英] cannot use the part (...) to traverse the element
问题描述
运行mongod
3.6并尝试使用此示例.
Running mongod
3.6 and attempting to use this example.
以下是示例数据:
> 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?
推荐答案
When switching from lower version to higher version for mongodb you have to set setFeatureCompatibilityVersion
for your mongodb which
启用或禁用保留与以下数据不兼容的数据的功能 MongoDB的早期版本.您只能发出 针对管理员数据库的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.
您可以通过在mongo shell中运行此命令来简单地进行设置
You can simply set this by running this command in mongo shell
db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
这篇关于无法使用零件(...)遍历元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!