Firebase Firestore - Can I perform normal reads inside transactions?

Viewed 29

Can I do the following inside a transaction or might it cause unexpected errors?

module.exports = function updateUser(id, transaction) {
   // A query between writes
   const query = firestore
       .collection("users")
       .where("id", ==, id);

   const querySnapshot = await query.limit(1).get(); // <--- Only getting one doc

   transaction.update(...
}

....

return firestore.runTransaction(async (transaction) => {
   /* Transaction reads... */
   const a = transaction.get(...


   /* Transaction writes... */
   transaction.create(...

   await updateUser(ADMIN_ID, transaction); // <------ Implicit query
});

As I don't really care about the query target doc's modifications, I am performing the query without using "transaction", as it is not valid to perform queries using the Transaction object.

But, is this correct? Is it valid to execute a normal read after some transaction writes?

0 Answers
Related