2 回答
![?](http://img1.sycdn.imooc.com/545868cd00013bbb02200220-100-100.jpg)
TA贡献1942条经验 获得超3个赞
您可以通过exists()在DocumentSnapshot对象上调用方法来检查特定文档是否存在于您的session集合中,从而在用户端解决此问题,如下所示:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
DocumentReference docRef = rootRef.collection("session").document(docId);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
//Add attendance record to the attendance collection
} else {
Log.d(TAG, "No such document");
}
}
}
});
为了 100% 确保您还可以使用安全规则,正如@Gerardo 在他的回答中提到的那样,您可以在其中再次使用exists()方法来查看会话集合中是否存在某个会话,并相应地拒绝该操作。
添加回答
举报