Delete Field in Firestore Document
You can try as shown below:
// get the reference to the doc
let docRef=this.db.doc(`ProfileUser/${userId}/followersCount/FollowersCount`);
// remove the {currentUserId} field from the document
let removeCurrentUserId = docRef.update({
[currentUserId]: firebase.firestore.FieldValue.delete()
});
This worked for me. (also worked to delete field with null value)
document.ref.update({
FieldToDelete: admin.firestore.FieldValue.delete()
})
For some reason the selected answer (
firebase.firestore.FieldValue.delete()
) did not work for me. but this did:
Simply set that field to null
and it will be deleted!
// get the reference to the doc
let docRef=this.db.doc(`ProfileUser/${userId}/followersCount/FollowersCount`);
// remove the {currentUserId} field from the document
let removeCurrentUserId = docRef.update({
[currentUserId]: null
});