Delete Field in Firestore Document

≯℡__Kan透↙ 提交于 2019-12-21 04:07:09

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/46984308/delete-field-in-firestore-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!