MongoDB 预定触发器保存错误 -- 要 Return 做什么?

MongoDB Scheduled Trigger Save Error -- What to Return?

这个问题很烦人。因此,我每 24 小时制作一个 计划触发器 运行。它只是从一个集合中获取项目并进行一些数据处理,然后将信息附加到另一个集合。 功能代码有效 即使功能 运行s。但是它不会让我保存,因为有“运行time”错误?尽管它执行得非常完美并且 returned.

控制台错误

> result (JavaScript): 
EJSON.parse('{"$undefined":true}')

我想这与 returning 有关。但是当我 return null 我得到这个:

> result: 
null
> result (JavaScript): 
EJSON.parse('null')

尝试保存时,我在页面顶部看到了这个:

runtime error during function validation

函数代码:

exports = async function() {
  const usersCol = context.services.get("SchoologyDashCluster").db("SchoologyDashApp").collection("users");
  const gradesCol = context.services.get("SchoologyDashCluster").db("SchoologyDashApp").collection("grades");
  var usersCusor = await usersCol.find( ).toArray();
  var gradesCusor = await gradesCol.find( ).toArray();
  let insert = [];
  for (let i = 0; i < usersCusor.length; i++) {
    var user = usersCusor[i];

    var userSavedGrades = gradesCusor[i].grades
    var currentGrades = await getGrades(user.schoologyUID, user.consumerKey, user.secretKey);
    
    var lastGraded = NaN;
    let index = gradesCusor[i].grades.length - 1;
    
    while (true) {
      if (gradesCusor[i].grades[index].changed == 1) {
        lastGraded = index;
        break
      }
      index = index - 1;
    }
    console.log(lastGraded)
    if (userSavedGrades[lastGraded].grades.ga == currentGrades.ga){
      currentGrades = { changed : 0, time: new Date().getTime()};
    } else {
      currentGrades = {changed : 1, grades: currentGrades, time : new Date().getTime()};
    }
    
    
    gradesCol.updateOne(
      {"user" : user._id},
      {"$push" : {"grades" : currentGrades}}
    )
  }
  // return usersCol.find( );
  
  
  return null;
};

答案很简单,现在我觉得很懵。本能地,我将模块导入放在文档的顶部。然而,这是不正确的,它们需要放在导出函数中,如下所示:

exports = function (x,y,z) {
 const http = context.http;
 return;
}