是否可以将Allusers集合的字段值(在这种情况下为gamerroomname)从另一个集合(在这种情况下为gameroom)访问/传递?
以便我可以在下面进行操作:
ref.collection("GameRooms").document(gameroomname).addSnapshotListener(){
}
游戏室截图:
尝试之后,下面的代码可以工作。但这是正确的方法还是有更好的方法:
mFirestore.collection("AllUsers").document(SplitString(currentUser.email!!)).get().addOnSuccessListener(OnSuccessListener<DocumentSnapshot> { documentSnapshot ->
var gameRoomName: String = ""
if (documentSnapshot.exists()) {
gameRoomName = documentSnapshot.getString("gameroomname")!!
}
mFirestore.collection("GameRooms").document(gameRoomName).collection("Words called").addSnapshotListener(EventListener<QuerySnapshot>(){ queryDocumentSnapshot, e->
selectedWordsList.clear()
if (!queryDocumentSnapshot!!.isEmpty) {
val gameRoomList = queryDocumentSnapshot.documents
for (doc: DocumentSnapshot in gameRoomList) {
var addWord: String = ""
if (doc.get("addword") != null) {
addWord = doc.get("addword").toString()
}
val selectedGameRoomList: SelectedWordsObject = SelectedWordsObject(addWord, false)
selectedWordsList.add(selectedGameRoomList)
mSelectedWordsAdapter.notifyDataSetChanged()
}
mSelectedWordsAdapter.notifyItemChanged(0)
}
else {
Toast.makeText(this@Screen, "Document does not exist", Toast.LENGTH_LONG).show()
}
})
}).addOnFailureListener(OnFailureListener { e->
val error=e.message
Toast.makeText(this@Screen,"Error:"+error, Toast.LENGTH_LONG).show()
})