Here is my sample code that is making many parallel writes to Firestore.
const admin = require('firebase-admin');
admin.initializeApp({credential: admin.credential.applicationDefault()});
const db = admin.firestore();
const main = async () => {
// Gather up documents and write to new app subcollection
startTimeMs = Date.now();
let commits = [];
let doc = {abc: "def"};
let total = 10;
for (let i=0; i<total; i++) {
commits.push(db.collection(`/test`).add(doc));
}
const bar = await Promise.all(commits);
console.log(bar);
const count = await db.collection(`/test`).count().get();
console.log("count", count);
};
(async () => {
await main();
})();
I tried total=10, 100, 1000.
When total is small (< 500), this code resolves quickly. However when total>500, this code takes a long time to finish.
In both cases, console.log("count", count);
gets executed fairly quickly and shows the right number of documents (doesn't seem like some promises are failing). But when total > 500, the main function takes a lot longer to finish running.
I was expecting for all cases, the function would finish after executing the last line.