2 回答

TA貢獻1942條經(jīng)驗 獲得超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% 確保您還可以使用安全規(guī)則,正如@Gerardo 在他的回答中提到的那樣,您可以在其中再次使用exists()方法來查看會話集合中是否存在某個會話,并相應地拒絕該操作。
添加回答
舉報