Encountering the error "Missing ";" before statement" in Mongodb Atlas Online is frustrating for me as a newbie. Despite my efforts, I can't seem to figure out why the following code snippets are causing this issue:
const counter = await counterCollection.findOneAndUpdate({_id: changeEvent.ns },{ $inc: { seq_value: 1 }}, { returnNewDocument: true, upsert : true});
AND:
const updateRes = await targetCollection.updateOne({_id: docId},{ $set: doc});
Here's the complete code:
exports = function(changeEvent) {
const docId = changeEvent.fullDocument._id;
const counterCollection = context.services.get("Cluster0").db(changeEvent.ns.db).collection("counters");
const targetCollection = context.services.get("Cluster0").db(changedEvent.ns.db).collection(changeEvent.ns.coll);
const counter = await counterCollection.findOneAndUpdate({_id: changeEvent.ns },{ $inc: { seq_value: 1 }}, { returnNewDocument: true, upsert : true});
const doc = {};
doc[`${changeEvent.ns.coll}Id`] = counter.seq_value;
const updateRes = await targetCollection.updateOne({_id: docId},{ $set: doc});
console.log(`Updated ${JSON.stringify(changeEvent.ns)} with counter ${counter.seq_value} result: ${JSON.stringify(updateRes)}`);
};