I am noticing a behaviour where data that I create using batch commit into a collection isn’t immediately available when querying. Here what I do:
// First Batch create documents from myData array. All of which have a property called ref = 'abc'
myData.forEach((el: DocDefinition) => {
const doc = db.collection(`some-path`).doc(el.email);
batch.create(doc, el);
}
});
// Later in the same context I query collection 'some-path' like so
query = await db.collection('some-path').where('ref', '==', 'abc').get();
query.empty; // => true
When I do the same query from firebase console, it returns results as expected, which makes me wonder if the query returning no results is because when the batch.commit() promise resolves, it doesn’t mean the data has been written. And so when the query happens right after, the data isn’t there yet.
If so, what’s the recommended way? Should I allow some time before querying or is there another solution?
1