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

153
Views
Javascript - Error Message : db.collection is not a function && How to check whether the write batch whether successfully upload the data to firestore
        // Get a new write batch
        const batch = writeBatch(db);

        var TransactionRecordRef = db.collection("TopUpRecord").doc();
        batch.set(TransactionRecordRef, {
            Amount: FinalTopUpAmount,
            DateTime: serverTimestamp(),
            StudentID: StudentID,
        });
               

        var TopUptoUserRef = db.collection("user").doc(UserID);
        batch.update(TopUptoUserRef, { "studentAmount": UserTotalAmount });

        batch.commit();

Hi, the above is my code that needs to use write batch to create a new document on TopUpRecord and update the user's amount. Now I have two questions that I need to ask one is how can I know whether the batch successfully updates the record to the firestorm and I also found that my above code has an error which "db. the collection is not a function" Is anyone why this issue happened?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're mixing the v8-and-before namespaced syntax (db.collection("TopUpRecord").doc()) with the v9-and-up modular syntax (writeBatch(db)), which isn't possible.

In the modular syntax, that line would be:

const TransactionRecordRef = doc(collection(db, "TopUpRecord"));

Also see the v9 examples in the Firebase documentation, and the upgrade guide.

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!