title: Is it possible to access a field value in one collection from another collection in firestore?
body: <p>Is it possible to access/pass field value(in this case gamerroomname) of Allusers collection from/to another collection(in this case gamerooms)?</p>
  
  <p>so that I can do below:</p>
  
  <pre><code>ref.collection("GameRooms").document(gameroomname).addSnapshotListener(){
  }
  </code></pre>
  
  <p>Screenshot of Allusers:
  <a href="https://i.stack.imgur.com/uy5sM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uy5sM.png" alt="enter image description here"></a></p>
  
  <p>Screenshot of Gamerooms:</p>
  
  <p><a href="https://i.stack.imgur.com/kZ6gY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZ6gY.png" alt="enter image description here"></a></p>
  
  <p>After trying,the below code works.But is this the correct way to do this or is there any way better:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> mFirestore.collection("AllUsers").document(SplitString(currentUser.email!!)).get().addOnSuccessListener(OnSuccessListener&lt;DocumentSnapshot&gt; { documentSnapshot -&gt;
              var gameRoomName: String = ""
              if (documentSnapshot.exists()) {
                  gameRoomName = documentSnapshot.getString("gameroomname")!!
              }
              mFirestore.collection("GameRooms").document(gameRoomName).collection("Words called").addSnapshotListener(EventListener&lt;QuerySnapshot&gt;(){ queryDocumentSnapshot, e-&gt;
                  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-&gt;
              val error=e.message
              Toast.makeText(this@Screen,"Error:"+error, Toast.LENGTH_LONG).show()
          })</code></pre>
  </div>
  </div>
  </p>