how to delete a Document Field in Cloud Firestore? ... I'm using the code below but I can not.
this.db.doc(`ProfileUser/${userId}/followersCount/FollowersCount`).update({
[currentUserId]: firebase.firestore.FieldValue.delete()})
Anyone know how to do it?
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()
});
Another solution that comes to my mind is, instead of focusing on updating the document deleting the field, update the entire document. Such as:
let data: Partial<ObjectType> = {
//some fields here,
thatField: '',
//some fields there
};
this.angularFirestore.collection('collection_name').doc<ObjectType>('id').set(data);
Also, instead of initializing that field you may simply not include it.