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

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

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 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