how can I delete a field in a document from a cloud firestore function ?
I'm using transactions, so I tried this approach :
const { FieldValue } = require('@google-cloud/firestore');
...
..
transaction.update(docRef, { fieldToRemove: FieldValue.delete() });
but I'm getting this error :
Transaction failure: Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Argument "dataOrField" is not a valid Document. Couldn't serialize object of type "DeleteTransform". Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the 'new' operator).
Thanks !
You're right to use FieldValue.delete()
as per the docs, but need to import it from 'firebase-admin' instead:
const admin = require('firebase-admin');
const FieldValue = admin.firestore.FieldValue;
transaction.update(docRef, { fieldToRemove: FieldValue.delete() });
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