[英]Delete data from firestore
I have add data on firestore Firebase but I don't have specific document because I use addSnapShotListener to retrieve the data. 我在firestore Firebase上添加了数据,但是没有特定的文档,因为我使用addSnapShotListener来检索数据。 How can I delete the document when I don't know the name of it. 当我不知道文件名时如何删除它。 Here is the code where I add the data: 这是我添加数据的代码:
mondayCollectionReference.document().set(userMap, SetOptions.merge()).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(TimeForm.this, "Submitted", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("ERROR", e.getMessage());
}
});
document()
returns a DocumentReference object. document()
返回一个DocumentReference对象。 That object gives you everything you need to know to delete it, especially its own delete()
method. 该对象为您提供了删除该对象所需的一切,尤其是它自己的delete()
方法。 It also has a getId()
method to help you remember its id. 它还具有getId()
方法来帮助您记住其ID。
So, you should store the DocumentReference object first before calling methods on it: 因此,您应该先存储DocumentReference对象,然后再对其调用方法:
DocumentReference ref = mondayCollectionReference.document()
String id = ref.getId();
ref.set(...);
// use ref or id later if you want to delete it
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.