Search code examples
firebaseangularfire2

How to remove a document field using AngularFirestore?


According to the Firestore docs one can do the following:

var cityRef = db.collection('cities').doc('BJ');

// Remove the 'capital' field from the document
var removeCapital = cityRef.update({
    capital: firebase.firestore.FieldValue.delete()
});

However, using AngularFirestore, FieldValue is not available:

enter image description here

How can one remove a field using AngularFirestore?

Edit:

  • Setting the field value to null does not remove the field
  • Setting the field value to undefined is not allowed

Solution

  • To use the FieldValue.delete() method you have to import:

    import * as firebase from 'firebase/app';
    

    or as camden_kid suggested:

    import { firestore } from 'firebase/app';