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");
const db = admin.firestore();
...
db
.collection("settings")
.doc("totalUsers")
.set({
count: firebase.firestore.FieldValue.increment(1),
});
And i just doesn't increment the counter at all. No errors no logs no nothing.
In my Firestore i have a collection of settings
and a document totalUsers
with a property count
that is a number type and it equals to 1.
Am I doing something wrong? Am I missing anything? Any help appreciated!
increment works with both update and set.
For it to actually increment the field you can:
merge: true
or mergeFields: "something"
, with something the name of the field being incrementedFor 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With