Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!