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

225
Vistas
how to fix "FirebaseError: Type does not match the expected instance." on firebase transaction. React.js

on my site, when a section is deleted I want all items in that section removed so I am using a transaction

        const sectionRef = db
            .collection('items')
            .where('subSection', '==', sectionName);

        db.runTransaction((transaction) => {
            return transaction
                .get(sectionRef)
                .then((data) => {                   
                    data.docs.map((doc) => {                        
                        transaction.delete(doc);
                    });
                })
                .catch((e) => {
                    console.log('transaction failed', e);
                });
        });
    };

i am getting the following error

(FirebaseError): Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?

here is the firebase config

firebaseConfig = {
        apiKey: process.env.REACT_APP_PROD_API_KEY,
        authDomain: process.env.REACT_APP_PROD_AUTH_DOMAIN,
        projectId: process.env.REACT_APP_PROD_PROJECT_ID,
        storageBucket: process.env.REACT_APP_PROD_STORAGE_BUCKET,
        messagingSenderId: process.env.REACT_APP_PROD_MESSAGING_SENDER_ID,
        appId: process.env.REACT_APP_PROD_APP_ID,
        measurementId: process.env.REACT_APP_PROD_MEASUREMENT_ID,
    };
    const firebaseApp = firebase.initializeApp(firebaseConfig);
    const db = firebaseApp.firestore();

can anyone see the issue?

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

0

With the JS SDK (and the other client SDKs: iOS, Android, C++) you cannot get the docs of a collection (or of a query) in a Transaction.

As you will see in the doc, you need to pass a DocumentReference to the get() method (of a Transaction).

You can call this get() method several times in the transaction, but you cannot pass a CollectionReference to it.


On the other hand, this is possible via the Admin SDKs (i.e. the server libraries). For example, with the Node.js one, see the doc for the get() method.

You can get more details about the difference between these SDKs, and their reasons, in this documentation item.


So, since you use a query it means that you don't now upfront (i.e. when coding) the list of the documents to read in the Transaction. So you should use the Admin SDK, for example in a Cloud Function.

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