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

116
Views
Meteor Collection Hooks: cómo ejecutar el gancho 'después de insertar' solo una vez que haya terminado el 'después de insertar' anterior

Las inserciones ocurren más rápido de lo que la función after.insert puede procesar y lo que quiero que suceda después de insertar el documento actual depende de lo que sucedió después de insertar el documento anterior.

Creo que la pregunta corta podría ser ¿cómo lo hago sincrónico?

 FirstCollection.after.insert(function (userId, doc) { lastDoc = SecondCollection.findOne({}, { sort: { $natural: -1 } }); if (!lastDoc) { SecondCollection.insert({ startNumber: doc.txNumber, count: 1, duration: 264, lastTx: doc.txNumber, time: Date.now(), finishedAt: 0, }); return; } if (lastDoc.finishedAt !== 0) { if (Date.now() - lastDoc.finishedAt < 60000) { return; } SecondCollection.insert({ startNumber: doc.txNumber, count: 1, duration: 264, last: doc.txNumber, time: Date.now(), finishedAt: 0, }); return; } SecondCollection.update( { _id: lastDoc._id }, { $set: { lastTx: doc.txNumber }, $inc: { count: 1 } } ); if (lastDoc.count === lastDoc.duration) { SecondCollection.update( { _id: lastDoc._id }, { $set: { finishedAt: Date.now() } } ); } });
about 4 years ago · Juan Pablo Isaza
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!