Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
MongoDB Scheduled Trigger Save Error -- What to Return?

This problem is very annoying. So, I am making a scheduled trigger run every 24 hours. It simply gets items from one collection does some data processing then appends information to another collection. The functioning code works even when the function runs. But it will not let me save because there are "runtime" errors? Even though it was executed perfectly and returned.

Console Error

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

I suppose this has something to do with returning. but when I return null I get this:

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

when trying to save I get this at the top of the page:

runtime error during function validation

Function Code:

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;
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The answer was simple and now I feel ignorant. Instinctual I put the module imports at the top of the document. However this is incorrect and they need to be placed in the exports function, like so:

exports = function (x,y,z) {
 const http = context.http;
 return;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda