Using 3.6, Array Updates fails in Node, ArrayFiletrs are being ignored

287 views
Skip to first unread message

Robert Abarbanel

unread,
Jan 12, 2018, 5:42:22 AM1/12/18
to mongodb-user
Just installed 3.6.
In the mongo shell I can run this command without problems
        db.images.update(
            {},
           {$set: { "files.$[elem].comment": "abc" )}   
          { arrayFilters: [{
                "elem.filename": "114T0231-5_30_NL2500_1_1_0001.jpg",
                "elem.dir": "/images/Tools/NL"
            }] })
 

When I run "the same" update in JavaScript under node having installed "mongodb": "^2.2.34":
db.collection('images').update(
query,
{
$set: { "files.$[elem].comment": comment }

},
{
arrayFilters: [{
$and: [
{
"elem.filename": filename
},
{
"elem.dir": dir
}
]
}]
}
).then(....)


I get this error:
{"name":"MongoError","message":"No array filter found for identifier 'elem' in path 'files.$[elem].comment'",
"driver":true,"index":0,"code":2,"errmsg":"No array filter found for identifier 'elem' in path 'files.$[elem].comment'"}

The mongo shell handles the arrayFilters, but it appears that the node driver does not.



Kevin Adistambha

unread,
Jan 21, 2018, 5:40:44 PM1/21/18
to mongodb-user

Hi Robert,

The arrayFilters operator is only supported in node driver 3.0.0 and newer. If you upgrade your node driver, the query should work as expected.

Please note that there are some breaking changes in node driver 3.0.0 vs. earlier version. The main change is that MongoClient.connect now returns a Client instead of a DB. Please see 3.0.0 changelog for more details.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages