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
})
Anyone tried this yet?
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:
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.However this is not true of the
mongo
shell, since the way the method is implemented there ( "ironically for backward compatibility" ) thearrayFilters
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.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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With