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

184
Views
Colecciones de Firestore - recursiveDelete() frente a eliminaciones por lotes

¿Qué se considera más eficiente al eliminar una colección de Firestore?

Realizar eliminaciones mediante lotes:

 async function deleteCollection(db, collectionPath, batchSize) { const collectionRef = db.collection(collectionPath); const query = collectionRef.orderBy('__name__').limit(batchSize); return new Promise((resolve, reject) => { deleteQueryBatch(db, query, resolve).catch(reject); }); } async function deleteQueryBatch(db, query, resolve) { const snapshot = await query.get(); const batchSize = snapshot.size; if (batchSize === 0) { // When there are no documents left, we are done resolve(); return; } // Delete documents in a batch const batch = db.batch(); snapshot.docs.forEach((doc) => { batch.delete(doc.ref); }); await batch.commit(); // Recurse on the next process tick, to avoid // exploding the stack. process.nextTick(() => { deleteQueryBatch(db, query, resolve); }); }

O usando el método recursiveDelete() predeterminado de firestore:

 await firestore.recursiveDelete(collectionRef);

Nota: La colección que intento eliminar no tiene subcolecciones anidadas. Además, estoy ejecutando este código en una función de nube.

 /messages (C) -message_id_1 (D) -message_id_2 (D) -message_id_3 (D) ... -message_id_10000 (D)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La función recursiveDelete utiliza el mismo mecanismo que las escrituras por lotes bajo el capó, por lo que cualquier diferencia de rendimiento debería ser insignificante.

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!