简体   繁体   English

MongoDB Stitch/Realm Function updateMany 出现聚合错误

[英]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.我正在尝试创建一个 function 来解锁在指定时间之前锁定的线索。 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... 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 StitchError:更新:修饰符参数必须是 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? updateMany 是否接受 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.嗨 Bernard – 聚合管道中的更新是 MongoDB(带有 4.2)中的一个相当新的功能,我们正在支持 MQL 到 MongoDB 4.4 在 Realm 函数中。 We expect this to be released in the near future.我们预计这将在不久的将来发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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