【发布时间】:2018-04-15 23:01:42
【问题描述】:
我有以下功能:
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()
});
更新
因此,使用网络等效项似乎可行:admin.firestore.FieldValue.delete()。但这似乎是一个错误,因为我在 nodejs 环境中?任何 Firebaser 都可以确认或否认这种情况吗?我很乐意提交错误报告。
【问题讨论】:
标签: javascript firebase google-cloud-functions google-cloud-firestore