I have the following function:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const FieldValue = require('firebase-admin').FieldValue;
module.exports = functions.firestore
.document('students/{studentId}')
.onDelete(event => {
const student = event.data.previous.data();
const { id, semester } = student;
const classId = student.class;
const deleteObj = {};
deleteObj[id] = FieldValue.delete();
return admin
.firestore()
.collection('semesters')
.doc(semester)
.collection('students')
.doc(classId)
.update(deleteObj);
});
Every time I run it, I get the following error:
TypeError: Cannot read property 'delete' of undefined
at module.exports.functions.firestore.document.onDelete.event (/user_code/deleteStudent.js:12:37)
Looking for docs I can’t understand what am I doing wrong?
var FieldValue = require("firebase-admin").FieldValue;
var cityRef = db.collection('cities').doc('BJ');
var removeCapital = cityRef.update({
capital: FieldValue.delete()
});
Update
Thus, the use of the Web equivalent seems to be working: admin.firestore.FieldValue.delete()
. But this seems like a bug, since I'm in a nodejs environment? Can any Firebaser confirm or deny this, or not? I will gladly write a bug report.
source
share