title: How to get data from google-cloud-firestore in to a global variable?
body: <p>I'm trying to create a web app that generates or view statistics reports. The data will be collected from an android app will get data from google-cloud-firestore(GCF) save this data in variables and make calculations like mean, media, plot etc. The issue I'm having is that I can only view the data from GCF on the console when I try to return data provided or put the data in a global variable the data doesn't appear. I want to know why this happens and also how to solve this issue. I believe is my shortcoming on understanding this technology, I already read the documentation but I don't know what concept I don't understand and doing it wrong. Please let your light of illuminate sages shine a bit upon me. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//firestore
  var admin = require("firebase-admin");
  
  var serviceAccount = require("./sis-restaurante-firebase-adminsdk-huzz9-7b82544553.json");
  
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://sis-restaurante.firebaseio.com"
  });
  
  var db = admin.firestore();
  
  globalTest = [1,2,3,4]
  var giveMyStuff = db.collection("pedidos")
          .onSnapshot(function(querySnapshot) {
              localTest = []
              querySnapshot.forEach(function(doc) {
                localTest.push(doc.data().statusitem);
                globalTest.push(doc.data().statusitem);
              });
              console.log("Estatus dos pratos: ", localTest.join(", "));  
  
          }
          );  
  
  
  
  console.log(giveMyStuff)
  console.log(globalTest)</code></pre>
  </div>
  </div>
  
      Console Output:
      [ 1, 2, 3, 4 ]
      Estatus dos pratos:  Em Preparo, Pronto, Em Preparo</p>
  
  <p>Thanks in advance. </p>