title: retrieve data from Firestore as json
body: <p>in firestore documentations i found this way to get multi data </p>
  
  <pre><code>db.collection("cities").where("capital", "==", true)
  .get()
  .then(function(querySnapshot) {
      querySnapshot.forEach(function(doc) {
          // doc.data() is never undefined for query doc snapshots
          console.log(doc.id, " =&gt; ", doc.data());
      });
  })
  </code></pre>
  
  <p>but this way i have to make two loop one in backend to handle and push data into object then another loop in frontend for display the data !! is there any way to escape the first loop and return list of data without handle it in loop in backend like that</p>
  
  <pre><code>return res.status(200).json(doc.data())
  </code></pre>
  
  <blockquote>
    <p>the answer</p>
  </blockquote>
  
  <pre><code>.get()
  .then(query=&gt;{
      let data = query.docs.map(doc=&gt;{
          let x = doc.data()
              x['_id']=doc.id;
              return x;
      })
      res.status(200).json(data);
  })
  </code></pre>
  
  <p>this answer will return an id of doc as part of data it-self</p>