Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Issue with Mongodb pre-defined javascript

I keep getting, Missing ";" before statement error in Mongodb Atlas Online. I am new to this, and I fail to see why the following lines gives this error:

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});

Full 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)}`);
};

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solve it, added async in front of function, and this eliminated the errors. Not sure why I not thought about this before. Sorry SO!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!