FieldValue undefined when using functions and Firestore

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(); //Line 12, this is where the error orccurs
    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?

// 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()
});

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.

+5
source share
1 answer

It turns out that it was a mistake in the documentation, the correct import should have been const FieldValue = require('firebase-admin').firestore.FieldValue;

Update

It should be said that Firebase responded within a few hours and corrected the documents as soon as possible.

+6

Source: https://habr.com/ru/post/1688671/


All Articles