Skip to content

Cloud firestore 0.10.0 FieldValue.increment not working  #31831

@kataklysmo

Description

@kataklysmo

I got a problem with concurrent transactions.
I'm using flutter with cloud firestore plugin version 0.10.0

I got a collection called counters with a document named test. Inside this document i got a field called counter ( number type).
This counter is increased pushing a button from different devices, that's when I understand that a transaction like this makes sense (I attach the piece of code I'm using).

DocumentReference counterRef = Firestore.instance.document("counters/test");

new FlatButton(
                            color: Colors.green,
                            child: new Text("ADD"),
                            onPressed: () {
                              Firestore.instance.runTransaction((Transaction tx) async {
                                DocumentSnapshot Ref = await tx.get(counterRef);
                                if(Ref.exists){
                                  print("Updating counter!");
                                  await tx.update(Ref , <String, dynamic>{
                                    'counter': FieldValue.increment(1),
                                  }).catchError((e){
                                    print("tx update err:$e");
                                  });
                                }else{
                                  print("No document found in transaction!");
                                }
                              });
                            },
                          ),

Using only 2 physical devices, hitting the button at once on both, the counter is only increased 1 time. And i can see on the logs that each device has called the transaction ( i see the Updating counter print on the console )

Can anyone check FieldValue.increment functionality from 2 devices at the same time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions