title: How to order document .add() data in firestore in Javascript
body: <p>Ive been struggling with ordering the documents in Cloud Firestore.
  Im using the collection.add() method. And reading the data and displaying it on the screen.</p>
  <p>Heres how i write it into the database:</p>
  <pre><code>let shared = {
                  category : category,
                  username : user.displayName,
                  createdAt : date,
              }
              // Add a new document with a generated id.
              const sharedRef = db.collection('shared');
              sharedRef.orderBy('createdAt', &quot;desc&quot;);
              sharedRef.add(shared)
                  .then(function() {
                      console.log(&quot;Saved to database&quot;);
                  }).catch(function(error) {
                  console.error(&quot;Error adding document: &quot;, error);
              });
  </code></pre>
  <p><a href="https://i.stack.imgur.com/3TdOz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3TdOz.png" alt="enter image description here" /></a>
  And to Read the data I just use <strong>doc.data forEach.</strong></p>
  <p>I Read the data with <strong>doc.data() forEach</strong></p>
  <p><strong>Is there anyway i can order the shared documents by the date created?</strong></p>