Mongodb 3.6.0-rc3数组过滤器不起作用吗? [英] Mongodb 3.6.0-rc3 array filters not working?

查看:46
本文介绍了Mongodb 3.6.0-rc3数组过滤器不起作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在mongodb 3.6.0-rc3中使用数组过滤器,就像在

I'm trying to use array filters in mongodb 3.6.0-rc3, exactly like in doc example but not getting any rows affected and no error.

示例已简化.我知道可以使用$作为位置运算符来完成此操作,但我打算将此功能用于两级嵌套数组.

Example is simplified. I know this can be done with $ as positional operator but I'm planing to use this feature for two level nested arrays.

db.getCollection('books').update({},
    {
        $set: { "authors.$[element].firstName": "Joe" }
    },
    {
        arrayFilters: [ { element: { "_id": ObjectId("some_id") } } ],
        multi: true
    })

有人尝试过吗?

推荐答案

您是否在robomongo中键入此内容?看起来像它!如果是这样,它将无法正常工作.在使用MongoDB更新嵌套数组上阅读我的笔记,我不会这样做在旧外壳"或基于它的任何东西(robomongo是基于外壳的构建)中工作,因为当前使用了外壳帮助器方法:

Are you typing this in robomongo? It looks like it! If so it won't work. Read my note on Updating a Nested Array with MongoDB where I say this does not work in an "older shell" or anything based on it ( which robomongo is a shell based build ) because of the way the shell helper methods are currently implemented:

注意有点讽刺意味的是,由于这是在.update()和类似方法的选项"参数中指定的,因此该语法通常与所有最新发行版驱动程序兼容.

NOTE Somewhat ironically, since this is specified in the "options" argument for .update() and like methods, the syntax is generally compatible with all recent release driver versions.

但是对于mongo shell却不是这样,因为在那里实现该方法的方式(具有讽刺意味的是为了向后兼容"),arrayFilters自变量不能由解析方法中的选项的内部方法识别和删除.为了提供与先前MongoDB服务器版本的向后兼容性"和旧版" .update() API调用语法.

However this is not true of the mongo shell, since the way the method is implemented there ( "ironically for backward compatibility" ) the arrayFilters argument is not recognized and removed by an internal method that parses the options in order to deliver "backward compatibility" with prior MongoDB server versions and a "legacy" .update() API call syntax.

因此,如果要在mongo shell或其他基于shell"的产品(特别是Robo 3T)中使用该命令,则需要从开发分支或生产版本开始的3.6或更高版本.

So if you want to use the command in the mongo shell or other "shell based" products ( notably Robo 3T ) you need a latest version from either the development branch or production release as of 3.6 or greater.

因此,如果您想试用"发行候选版本,请使用捆绑的mongo shell与该版本一起使用,或者直接通过任何标准驱动程序运行代码.

So if you want to "play with" the release candidate, either use the bundled mongo shell with that version or simply run your code through any standard driver.

这篇关于Mongodb 3.6.0-rc3数组过滤器不起作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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