I have the following query:
db.COLLECTIONNAME.update({ groupId:11 },{ $set: { "users.$[elem1].preferred_username": 'cmaronchick2'} },{ arrayFilters: [ {"elem1.username":'cmaronchick'} ] })
My Mongo server version is 3.6.6. I have tried this using the shell and it works.
However, when I try the same query using a Lambda function using Node.js on AWS, I get the following error:
No array filter found for identifier \'elem1\'
How do I resolve this?
Here is the connection code:
var mongo = require("mongodb").MongoClient,
assert = require("assert");
const MONGO_URL = 'mongodb://USERNAME:PASSWORD@MONGODBURL:PORT/DBNAME';
// console.log('Loading function');
exports.handler = (event, context) => {
console.log('Received event:', JSON.stringify(event, null, 2));
mongo.connect(MONGO_URL, function (err, db) {
db.COLLECTIONNAME.update({ groupId:11 },{ $set: { "users.$[elem1].preferred_username": 'cmaronchick2'} },{ arrayFilters: [ {"elem1.username":'cmaronchick'} ] })
}