0
votes

I'm newbie to Google Cloud Firestore in Database mode, and I have a question about its transaction.

If there are two entities which belong to the same entity group, does an update of one entity on a transaction inhibits an update of the other entity on another transaction?

I show an example case below.

Entity A:
    Key: 
        Kind: Foo, id: 0, Parent: "P"
    Properties:
        description: "I am A."
Entity B:
    Key:
        Kind: Foo, id: 1, Parent: "P"
    Properties:
        description: "I am B"

TRANSACTION #1 BEGIN;
A.description = "I am new A";

TRANSACTION #2 BEGIN;
B.description = "I am new B";

TRANSACTION #1 COMMIT; -- *1
TRANSACTION #2 COMMIT; -- *2

Does *1 or *2 succeed?

Thanks!

1

1 Answers

2
votes

If there are two entities which belong to the same entity group, does an update of one entity on a transaction inhibits an update of the other entity on another transaction?

No and it's not about an OR is about an AND, so both transactions will be committed. As I understand from you schema, you try to use a transaction to update two separate documents, which will always work. It will also always work even if you whould have tried to update the same document, the order of commits being the order in which you call commit() on the transaction objects. So the result of your commits will be:

Entity A:
    Key: 
        Kind: Foo, id: 0, Parent: "P"
    Properties:
        description: "I am new A."
Entity B:
    Key:
        Kind: Foo, id: 1, Parent: "P"
    Properties:
        description: "I am new B"