title: Include the document id as a field id in firestore
body: <p>Heres what i am trying to achieve i want a unique id field for every document in my database and i want that unique id to the same as the document id.</p>
  
  <p>Example:</p>
  
  <pre><code>documents:       data:
  
  eBgdTRE123       id:'eBgdTRE123'
                   name:'Jhon Doe'
                   job:'Programmer'     
  </code></pre>
  
  <p>i want i databse to have this structure, now i got two ideas to achieve this</p>
  
  <p>1: to use cloud function and have <code>onCreate</code> listener and everytime theres a new document grab document and set the id field and update it heres how i am doing it</p>
  
  <pre><code>exports.addDocIdToField = 
  
  functions.firestore.document('collectionname/{docID}').onCreate((snap,context) =&gt; {
      const id = context.params.docID;
      return admin.firestore().collection('collectionname')
          .doc(id).set({ id: snap.id }, { merge: true })
          .then(() =&gt; {
              return null;
          })
          .catch((error) =&gt; {
              return null;
          });
  })
  </code></pre>
  
  <p>2: to use the above kind of method on document creation. add a new document as soon as that document is added get the newly added document and update its <code>id</code></p>
  
  <p>both of them work but my question is can i rely on this kind of operation? i mean if the <code>id</code> is by any means <code>undefined</code> it can cause an error further in the app.</p>
  
  <p>or if there are other ways to achieve this?</p>