不能使用部件 (...) 来遍历元素 [英] cannot use the part (...) to traverse the element

查看:47
本文介绍了不能使用部件 (...) 来遍历元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 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?

推荐答案

mongodb从低版本切换到高版本时需要设置setFeatureCompatibilityVersion 用于您的 mongodb 其中

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆