I am trying to create a function to unlock leads that were locked before the specified time. I tested the updateMany function with an aggregation pipeline in the shell, but when trying to run it from a Realm Function I get an error...
StitchError: update: modifier argument must be an object
exports = function(){
const mongodb = context.services.get("mongodb-atlas");
const leads = mongodb.db("Dev").collection("leads");
const query = { lockDate: {$lte: new Date('2020-07-01T00:00:02.012Z')}, stage: "Lead" };
const update = [{ $set: {"previousOwner": "$owner", "locked": false}}, {$unset: ["owner", "lockDate"]}]
const options = { upsert: false };
return leads.updateMany(query, update, options).then(res => {
const { matchedCount, modifiedCount } = res;
console.log(`Successfully matched ${matchedCount} and modified ${modifiedCount} items.`);
return res;
}).catch(err => console.log(err));
};
Does updateMany accept aggregation pipelines in Realm? If it does did I make an error?