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!
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.