Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
runTransaction: Provided document reference is from a different Firestore instance error

I'm trying to implement easier to read documentIDs and through this strategy that Frank recommended but I've run into an error that I haven't been able to fix.

I can successfully read the value of highestCount from the COUNTER document but have an error when I try to update it.

The error states:

FirebaseError: Provided document reference is from a different Firestore instance

My Javascript code (using React):

const onSetCreation = async (e) => {
        e.preventDefault();
        var setNo = 0;
        try {
            await runTransaction(db, async (transaction) => {
                const currentSetNo = await transaction.get(
                    doc(db, "users", userStatus.uid, "set", "COUNTER")
                );
                console.log(currentSetNo.data());

                // if theres no counter, create one
                if (!currentSetNo.exists()) {
                    transaction.update({ highestCount: 0 });
                    setNo = 0;
                } else {
                    setNo = currentSetNo.data().highestCount + 1;
                    // update the COUNTER once iterated
                    transaction.update(currentSetNo, { highestCount: setNo });
                }
            });
            // succesful update of COUNTER
            console.log("Transaction successfully committed!");
        } catch (e) {
            console.log(e);
        }
    };

This function is triggered on a button click.

My Firestore structure

is users -> [userid] -> set -> COUNTER

Where counter is a document that holds highestCount which is to be updated everytime this function runs.

I'm able to console.log the value of COUNTER, just can't update it.

I haven't been able to find any similar problems.

I'm using the Web version 9 of Firestore, I've read this documentation for runTransaction.

Cheers

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Okay, so I found the error. I was using the wrong reference in this line:

transaction.update(currentSetNo, { highestCount: setNo });

which should actually be

transaction.update(
                    doc(db, "users", userStatus.uid, "set", "COUNTER"),
                        { highestCount: setNo }
                    );

Or whatever your db reference is, in replacement of currentSetNo in the first example.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda