async ((collection) => { var data = await(db.collection(collection).limit(10).get()); // Database is cleared if(data.size === 0) { return console.log('Database cleared'); } // Delete documents in a batch var batch = db.batch(); data.docs.forEach((doc) => { batch.delete(doc.ref); }) var deletedData = await(batch.commit()); console.log('deleted batch size: ', data.size); // Recurse on the next process tick, to avoid // exploding the stack. process.nextTick(() => { clearData(collection); }) })