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

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

问题描述

我正在尝试在 mongodb 3.6.0-rc3 中使用数组过滤器,就像 doc 示例 但没有影响任何行,也没有错误.

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 是基于 shell 的构建),因为 shell 帮助程序方法当前的实现方式:

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天全站免登陆