Firebase Firestore Increment FieldValue does not increment

后端 未结 3 1156
抹茶落季
抹茶落季 2021-01-28 23:27

so i\'ve read all the documentation everything about increment a counter in a Firestore database. I have this code

const admin = require(\"firebase-admin\");
co         


        
相关标签:
3条回答
  • 2021-01-29 00:15

    For anyone having issues with this, be careful to use the .update() method instead .set(). Also you need to have a value existing in the firestore that so it has something to increment.

    0 讨论(0)
  • 2021-01-29 00:16

    Since you are using the Admin SDK, you should do as follows:

    count: admin.firestore.FieldValue.increment(1)
    
    0 讨论(0)
  • 2021-01-29 00:22

    Try with this: (this is my code and works for me)

         var firebaseUser = await FirebaseAuth
                            .instance
                            .currentUser();
         DocumentReference queri = Firestore.instance
                             .collection("users")
                            .document(firebaseUser.uid);
                                                        Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => LoginView()));
    var loginSuccess = wait model.getdata(_inputCuit.text);
     if (loginSuccess) {
     queri.updateData({ "queries": FieldValue.increment(1)});}
    

    The key area is the .increment() method

    0 讨论(0)
提交回复
热议问题