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

270
Vistas
Javascript - FirebaseClould Issues: Cannot read properties of undefined (reading 'path')
        // Get a new write batch
        const batch = writeBatch(db);
        var TransactionRecordRef = doc(collection(db, "TopUpRecord"));
        batch.set(TransactionRecordRef, {
            Amount: FinalTopUpAmount,
            DateTime: serverTimestamp(),
            StudentID: StudentID,
        });


        //var TopUptoUserRef = doc(collection(db, "user"));

        const UQuery = query(collection(db, "user"), where("studentID", "==", StudentID));
        batch.update(UQuery, { "studentAmount": increment(FinalTopUpAmount) });

        batch.commit();

@firebase/firestore: Firestore (9.8.1): AsyncQueue Failed to persist write: TypeError: Cannot read properties of undefined (reading 'path')

enter image description here

I would like to use writebatch to update the studentAmount Field which searches based on the studentID but it keeps on popping up an error message @firebase/firestore: Firestore (9.8.1): AsyncQueue Failed to persist write: TypeError: Cannot read properties of undefined (reading 'path'). Does anyone know why this kind of issue and is there any solution?

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

0

Upon reviewing your code above, you only queried the document(s) which lacks execution of the query. You need to call the getDocs method to retrieve the documents. See sample code below:

import { getDocs } from "firebase/firestore";

// Get a new write batch
const batch = writeBatch(db);
var TransactionRecordRef = doc(collection(db, "TopUpRecord"));
batch.set(TransactionRecordRef, {
    Amount: FinalTopUpAmount,
    DateTime: serverTimestamp(),
    StudentID: StudentID,
});


//var TopUptoUserRef = doc(collection(db, "user"));

const UQuery = query(collection(db, "user"), where("studentID", "==", StudentID));

// Get the documents from `Uquery`
const querySnapshot = await getDocs(UQuery);
// Loop all the retrieved documents
querySnapshot.forEach((doc) => {
  // Get the document reference by using `doc.ref`
  batch.update(doc.ref, { "studentAmount": increment(FinalTopUpAmount) });
});

batch.commit();

Added some comments on the above code. For more information, you may check this documentation.

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