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

369
Visualizações
'RestConnection Commit failed with error' when trying to write to firestore

I am getting the following error when trying to write to Firestore. This is done in JavaScript(React).Can anyone tell what is this and how can I fix this?

@firebase/firestore: Firestore (8.3.1): RestConnection Commit failed with error:  {"code":"failed-precondition","name":"FirebaseError"} url:  https://firestore.googleapis.com/v1/projects/{project name}/databases/(default)/documents:commit request: {"writes":[{"update":{"name":"projects/{project name}/databases/(default)/documents/teams/T22yKl1ERQSlfuZNitrvs2vRjSJ2/team-analytics/T22yKl1ERQSlfuZNitrvs2vRjSJ2-Dec-22-2021","fields":{"homePageViews":{"integerValue":"3"},"timeModified":{"timestampValue":"2021-12-22T09:32:00.000000000Z"}}},"updateMask":{"fieldPaths":["homePageViews","timeModified"]},"currentDocument":{"updateTime":"2021-12-22T09:23:08.916511000Z"}}]}

My code that is trying to access Firestore is shown below:

return db.runTransaction(async (transaction) => {
    const analyticsDoc = await transaction.get(analyticsReference);

    if (analyticsDoc.exists) {
        const analytics: any = analyticsDoc.data();
        return transaction.update(analyticsReference, { homePageViews: analytics.homePageViews + 1, timeModified: getCurrentDateTime() });
    }
    const newAnalytics: AnalyticsObject = {
        totalViews: 0,
        homePageViews: 1,
        timeModified: getCurrentDateTime(),
    };
    return transaction.set(analyticsReference, newAnalytics);
});

I am also getting the following error in my console:

POST https://firestore.googleapis.com/v1/projects/optimx-sports/databases/(default)/documents:commit 400

Edit: After more digging in, I am thinking it might be because I am sending 2 transactions to the same document simultaneously. Is it possible that this error is because of this?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The issue was that I was sending two transaction commits to one firestore document within a second. The second commit was raising the above error. Fixed it by combining the two commits

about 4 years ago · Juan Pablo Isaza Relatório

0

Below are a few Points you can check with:

  1. In Cloud Firestore, you can only update a single document about once per second, which might be too low for some high-traffic applications. Have a look at Firestore documentation.

  2. You can refer to the Documentation.

  3. Also You can try with Postman API to access data.

  4. Another way is combining two commits as well.

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