title: Firestore query: getting data and storing it into an variable . How to use that variable in cloud functions?
body: <p>To get a data from the firestore I queried a document and get that data into variable. Now, I need to use that variable in other part of the code.
  when I am using that variable it does not get any data . How to resolve these error.</p>
  
  <pre><code>var d1;
                      var getdata = respond.get()
                                      .then(doc =&gt;{
                                      if(!doc.exists){
                                      console.log('No such document');
                                      }else{
                                      console.log('Document data:', doc.data());
                                       d1 = doc.data();// In d1 I am  not getting the data of that document 
                                      }
                                      }).catch(err =&gt; {
                                      console.log('Error getting documnet', err);
                                      });
  </code></pre>
  
  <p>Here in for loop, I am using the d1 variable. But it is not executing these for loop</p>
  
  <pre><code>for(var k in d1){
                       var p = d1[k].PhoneNumber;
                       let rph = respond.where(receiverph ,"==", p)
                                      .set({
                                      Status : status
                                      });
                                      let payload = {
                                          notification : {
                                          title: "Message",
                                          body: msg,
                                           sound:"default",
                                           }
                                      };
                                      console.log(payload);
                                      return admin.messaging().sendToDevice(token,payload).then((response) =&gt;{
                                      console.log(token);
                                      console.log("Successfully sen notification");
                                      }).catch(function(error){
                                      console.warn("Error sending notification",error);
                                      });
  
  
                       }
  
  
                      });
  </code></pre>
  
  <p>In d1 the data is</p>
  
  <pre><code>{ Invite2: { PhoneNumber: 917893659558, Amount: 33 },
    Invite1: { PhoneNumber: 917799266509, Amount: 33 },
    Invite3: { Amount: 33, PhoneNumber: 918639146409 } 
  }
  </code></pre>