title: How to get all documents from collection according to specific field from Firestore
body: <p>I have this data in "Firestore", I want to get all documents according to "city" like all users who have city "karachi" and stored in <code>arrayList</code> of type "chatModel" I want to show this data in recyclerView</p>
  
  <p>Here is the image of dataabase:<br>
  <a href="https://i.stack.imgur.com/oR2z6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oR2z6.png" alt="Here is the image of dataabase"></a></p>
  
  <p><strong>I have tried this but it's only getting me the last document from collection.</strong></p>
  
  <pre><code>      firestore.collection("USERS")
          .whereEqualTo("city",cityName)
          .get()
          .addOnSuccessListener { documents -&gt;
              for (document in documents) {
  
                  arrayList.add(document.toObject(chatModel::class.java))
  
                  Log.i("Info", "${document.id} =&gt; ${document.data}")
  
  
              }
  
              val adapter = chatAdapter(context!!, arrayList)
              chatRecyclerView.layoutManager = LinearLayoutManager(context,
                  LinearLayoutManager.VERTICAL,false)
              chatRecyclerView.adapter = adapter
              adapter.notifyDataSetChanged()
          }
  </code></pre>
  
  <p><strong>Here is the Logcat result:</strong></p>
  
  <pre><code>v21GH5sBi3SdIb3v3xsp3ob64S23 =&gt; {username=Muhammad Rizwan, Email=mr1017753@gmail.com, city=Karachi, ProfileImageUrl=https://firebasestorage.googleapis.com/v0/b/me2wee-1b547.appspot.com/o/USERS-MEDIA%2Fv21GH5sBi3SdIb3v3xsp3ob64S23?alt=media&amp;token=193c4013-c580-45dc-b63d-fee1ef13caba}
  </code></pre>
  
  <p>Here is the screenshot of all documents which contain the city "Karachi" but it's only getting the last one</p>
  
  <p><a href="https://i.stack.imgur.com/jJF44.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jJF44.png" alt="enter image description here"></a></p>