I want to implement auto-incremented fields with MongoDB Atlas triggers. However, by following the instruction from official MongoDB website. I still face an error > error: unknown: Unexpected reserved word 'await'. (46:18)
message as I run the code in the setting of trigger. The line number is pointing to the first line of await function. Below is the function I write for setting the trigger. Can anyone help me with this problem?
exports = function(changeEvent) { var docId = changeEvent.fullDocument._id; const countercollection = context.services.get("Cluster0").db("test").collection("counters"); const samplecollection = context.services.get("Cluster0").db("test").collection("samples"); var counter = await countercollection.findOneAndUpdate({_id: changeEvent.ns },{ $inc: { seq_value: 1 }}, { returnNewDocument: true, upsert : true}); var updateRes = await samplecollection.updateOne({_id : docId},{ $set : { sampleId: counter.seq_value}}); console.log(`Updated ${JSON.stringify(changeEvent.ns)} with counter ${counter.seq_value} result : ${JSON.stringify(updateRes)}`);};