title: Firestore : how to get latest updated document from collection
body: <p><a href="https://i.stack.imgur.com/7mD6h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7mD6h.png" alt="Firestore database structure"></a></p>
  
  <p>As shown in attached image chat_test is collection name and i created documents with random name. i want to access updated document if any change happen.what query i need to write?</p>
  
  <p>Here is my code.</p>
  
  <pre><code>firestore.collection('chat_test')
  .orderBy('updated_at', 'desc')
  .limit(1)
  .onSnapshot((snapshot) =&gt; {
     //console.log('success=&gt;',JSON.stringify(snapshot));
  
      snapshot.forEach(function(doc) {
       firestore.collection('chat_test/'+doc.id+'/messages').orderBy('message_time', 'desc').limit(1).onSnapshot((snap) =&gt; {
          console.log(snap);
          snap.forEach(function(doc) {
              console.log(doc.id,doc.data());
          });
       }, (error) =&gt; {            
        console.log('error',error);
      });
      });
  }, (error) =&gt; {
    console.log('error',error);
  });
  </code></pre>
  
  <p>i added updated_at new key in document.is there any other way to do?</p>