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.
var d1;
var getdata = respond.get()
.then(doc =>{
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 => {
console.log('Error getting documnet', err);
});
Here in for loop, I am using the d1 variable. But it is not executing these for loop
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) =>{
console.log(token);
console.log("Successfully sen notification");
}).catch(function(error){
console.warn("Error sending notification",error);
});
}
});
In d1 the data is
{ Invite2: { PhoneNumber: 917893659558, Amount: 33 },
Invite1: { PhoneNumber: 917799266509, Amount: 33 },
Invite3: { Amount: 33, PhoneNumber: 918639146409 }
}