While running the below in a cron job:
FutureTasks.upsert({
number: contentObj.records[i].number,
userid: contentObj.records[i].assigned_to_userid,
username: contentObj.records[i].assigned_to,
assignment_group: contentObj.records[i].assignment_group
}, {
// Modifier
$set: {
start_date: moment(contentObj.records[i].start_date, "YYYY-MM-DD HH:mm:ss").subtract(1, 'hours').format("YYYY-MM-DD HH:mm:ss"),
end_date: moment(contentObj.records[i].end_date, "YYYY-MM-DD HH:mm:ss").add(1, 'hours').format("YYYY-MM-DD HH:mm:ss")
}
}
,
function (err, doc) {
if (err) {
console.log('error inside upsert : ', err.reason);
future.throw(err);
} else {
console.log('doc inside upsert : ', doc);
future.return(doc);
}
}
);
}
}
try {
return future.wait();
}
catch (err) {
throw new Meteor.Error("insert-error", err);
}
},
I get correct response on console:
doc inside upsert : { numberAffected: 1 }
and database is inserted (first run) or updated (in subsequent runs)
But at the same time also:
Exception in callback of async function: Error: Future resolved more than once
How to resolve such issue as I need to run the above code in a recurring cron loop?
Or I need to do db.close?
Thanks so much.