Delete Field in Firestore Document

2020-02-28 03:31发布

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?

2条回答
Bombasti
2楼-- · 2020-02-28 04:25

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()
});
查看更多
看我几分像从前
3楼-- · 2020-02-28 04:26

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.

查看更多
登录 后发表回答