Firestore : RPC "commit" failed with status: 400 response; FAILED_PRECONDITION

Viewed 196

I am using Firestore in a React App and I see this error whenever there are two parallel request.

What does this error mean exactly?

Firestore (4.5.0) 2017-11-05T16:39:32.783Z: RPC "commit" failed with 
status: 400 response text: {
  "error": {
    "code": 400,
    "message": "the stored version (1509899972098969) does not match 
 the required base version (1509899938109577)",
     "status": "FAILED_PRECONDITION"

This is my code. It is a like system.

await getUserVotesRef().set({ userVotes }, { merge: true });

await fs.runTransaction(t =>
  t.get(coinVoteRef).then(doc => {
    // Add one person to the city population
    let coinIdCount = (doc.exists && doc.data()[coinId]) || 0;

    coinIdCount = !currVote ? coinIdCount + 1 : coinIdCount - 1;
    coinIdCount = coinIdCount >= 0 ? coinIdCount : 0;

    t.set(coinVoteRef, { [coinId]: coinIdCount }, { merge: true });
  })
);
0 Answers
Related