Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda