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

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

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 Report

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