delete a document in firebase when you know the field value

天大地大妈咪最大 提交于 2021-01-29 09:20:01

问题


Context: In the frontend the user can enter of delete dates for availability. This is how I added a date:

Firestore.instance.collection('availableDates').add({
        'availableDates':date});

But I also need to delete a document from a collection in Firestore. I don't know the document id but I know the the field value which is unique. How would I go about deleting the document if I know the field value within the document. Here is a screen shot of firestore:


回答1:


You can fetch the document first and then delete the document. For example:

refUser.where("city", isEqualTo: "CA").getDocuments().then((snapshot){
  snapshot.documents.first.reference.delete();
});


来源:https://stackoverflow.com/questions/56341378/delete-a-document-in-firebase-when-you-know-the-field-value

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