简体   繁体   中英

MongoDB Stitch/Realm Function updateMany with aggregation error

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?

Hi Bernard – Updates within the aggregation pipeline are a pretty new feature in MongoDB (with 4.2) and we're in the process of supporting MQL up to MongoDB 4.4 in Realm Functions. We expect this to be released in the near future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM