Im using NodeJs within google cloud functions and I want to increase the value of one parameter in one document
I initiate Firestore:
const Firestore = require('@google-cloud/firestore');
const PROJECTID = 'XXXX';
const firestore = new Firestore({
projectId: PROJECTID,
timestampsInSnapshots: true
});
And my .get() and .set() functions work correctly. But when I try to update a value incrementing it, I get errors with FieldValue.increment
I've tried:
await snapshot.ref.update({ parameter: FieldValue.increment(1) });
adding:
const FieldValue = require('firebase-admin').firestore.FieldValue;
await snapshot.ref.update({ parameter: FieldValue.increment(1) });
as explained in other sites, and:
documentRef.update(
'parameter', Firestore.FieldValue.increment(1)
)
as explained in https://cloud.google.com/nodejs/docs/reference/firestore/latest/firestore/fieldvalue
const admin = require('firebase-admin');
increment = admin.firestore.FieldValue.increment(1);
await snapshotRef.update({ parameter: increment });
But none work.
Error:
TypeError: admin.firestore.FieldValue.increment is not a function
or
TypeError: FieldValue.increment is not a function
"dependencies": {
"firebase-admin": "^6.5.1",
"nodemailer": "^6.6.1"
}