gpt4 book ai didi

javascript - 使用函数和 Firestore 时 FieldValue 未定义

转载 作者:行者123 更新时间:2023-12-03 01:28:50 25 4
gpt4 key购买 nike

我有以下功能:

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 都可以确认或否认情况是否如此吗?我很乐意提交错误报告。

最佳答案

事实证明这是文档中的错误,正确的导入应该是 const FieldValue = require('firebase-admin').firestore.FieldValue;

更新

应该说,Firebase 在数小时内做出了响应,并正在尽快更正文档。

关于javascript - 使用函数和 Firestore 时 FieldValue 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47091940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com