title: How to use Firestore databse : addSnapshotListener using await() in Kotlin?
body: <p>I have a DAO class where I have fetchHubList method which fetches a collection of documents from cloud Firestore asynchronously using await(). This implementation used the &quot;get()&quot; method which I got to know later on does not fetch real-time updates. On trying to implement the code similarly using onSnapshotListener gives an error (which was quite expected to be honest, because get() and this methods return quite different things). Does anyone have any idea how to implement this?</p>
  <p>How the code is currently:</p>
  <pre><code> suspend fun fetchHubList(): ArrayList&lt;HubModel&gt;? = try {
          val hubList = ArrayList&lt;HubModel&gt;()
  
          hubsListCollection.get().await().map { document -&gt;
  
              if (document != null) {
  
                  Log.d(TAG, &quot;Data fetch successful!&quot;)
                  Log.d(TAG, &quot;the document id is ${document.id}&quot;)
  
                  val temp = HubModel(document.get(&quot;hubName&quot;).toString(),
                                      document.id.toString(),
                          document.get(&quot;isAdmin&quot;) as Boolean)
                  hubList.add(temp)
  
                       //   hubList.add(document.toObject(HubModel::class.java))
  
              } else {
                  Log.d(TAG, &quot;No such document&quot;)
              }
  
          }
  </code></pre>
  <p>And what I want to implement here (and which is totally erroneous):</p>
  <pre><code>suspend fun fetchHubList(): ArrayList&lt;HubModel&gt;? = try {
          val hubList = ArrayList&lt;HubModel&gt;()
  
          hubsListCollection.addSnapshotListener().await().map { document -&gt;
  
              if (document != null) {
  
                  Log.d(TAG, &quot;Data fetch successful!&quot;)
                  Log.d(TAG, &quot;the document id is ${document.id}&quot;)
  
                  val temp = HubModel(document.get(&quot;hubName&quot;).toString(),
                                      document.id.toString(),
                          document.get(&quot;isAdmin&quot;) as Boolean)
                  hubList.add(temp)
  
                       //   hubList.add(document.toObject(HubModel::class.java))
  
              } else {
                  Log.d(TAG, &quot;No such document&quot;)
              }
  
          }
  </code></pre>
  <p>I use this function in my ViewModel class to create a LiveData wrapped ArrayList:</p>
  <pre><code>val hubList =  MutableLiveData&lt;ArrayList&lt;HubModel&gt;&gt;()
      private val hubListDao = HubListDao()
      init {
          viewModelScope.launch {
  
              hubList.value = hubListDao.fetchHubList()
          }
      }
  </code></pre>
  <p>Thanks in advance!</p>