title: How to keep data from a Firestore Query in a variable?
body: <p>I can't get the values of apps in a query in Firestore. I want to render with EJS the values of the groups and the apps collection but after the THEN from firestore the values of apps get deleted and I cant use them after. </p>
  
  <p>I tried with lodash const <code>appsClone = _.cloneDeep(apps);</code> but no success.</p>
  
  <p>The apps collection is inside the groups collection.</p>
  
  <p>Here is the example of what I'm trying to do:</p>
  
  <pre><code>let groups = [];  
  let apps = [];
  const db = admin.firestore();
  const group = db.collection('groups').where('roleId', '==', req.session.idRol);
        group.get()   // Trying to get all the groups
        .then(snapshot =&gt; {
             snapshot.docs.forEach(grp =&gt; {                        
             groups.push(grp.data());  // I can get all the groups without any problem
             grp.ref.collection('apps').get() // once I get the groups I try to get the APPS collection inside every group
             .then(snapshot2 =&gt; {
                   snapshot2.docs.forEach(app =&gt; {
                      apps.push(app.data()); // I can get the values of app and apps without any problem
                      console.log(apps); // I can get the value here of apps still
                    })
      // Now I cant get the value 
      // And I cant render here because I need the missing groups in the last forEach
              })                        
       });
       console.log("APPS: " + apps);   // Here apps is empty
       res.render("pages/launchpad", { groups, apps }); // Get to render groups but varible apps is empty.
       })
       .catch(err =&gt; {
            console.log(err);
       })
       });
       })
       .catch(err =&gt; {
          console.log(err);
       })
  </code></pre>
  
  <p>I really appreciate the help, have a good day.</p>