Each time I click a button on my site I would like to 'updateDoc' increase the value of the number in the database with something similar the the Javascript ++
I was wondering if this is possible and if its not what else can i do?
Each time I click a button on my site I would like to 'updateDoc' increase the value of the number in the database with something similar the the Javascript ++
I was wondering if this is possible and if its not what else can i do?
Firestore has a increment()
function that you can use to increment a field while updating a document.
import { doc, updateDoc, increment } from "firebase/firestore";
const docRef = doc(db, "collection", "DOC_ID");
await updateDoc(docRef, {
field_name: increment(1)
});