我有以下功能:
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(); //Line 12,this is where the error orccurs return admin .firestore() .collection('semesters') .doc(semester) .collection('students') .doc(classId) .update(deleteObj); });
每次运行它我都会收到以下错误:
TypeError: Cannot read property 'delete' of undefined at module.exports.functions.firestore.document.onDelete.event (/user_code/deleteStudent.js:12:37)
看着docs我真的不知道我做错了什么?
// Get the `FieldValue` object var FieldValue = require("firebase-admin").FieldValue; // Create a document reference var cityRef = db.collection('cities').doc('BJ'); // Remove the 'capital' field from the document var removeCapital = cityRef.update({ capital: FieldValue.delete() });
更新
因此,使用Web等效工具似乎有效:admin.firestore.FieldValue.delete().但这似乎是一个bug,因为我在nodejs环境中?任何Firebaser都可以确认或拒绝这种情况吗?我很乐意提交错误报告.