I try to get data from cloud firestore inside my actions on google app. I want to search for an object and then want to extract the link to the image in to an array. If more objects were found the links should be pushed all in the array.
This is what I have:
let array = []; //Everything should be in here
var collectionRef = db.collection('shoes');
var query = collectionRef.where('sport', '==', 'tennis');
query.get().then(function(results) {
if(results.empty) {
console.log("No documents found!");
} else {
// go through all results
results.forEach(function (doc) {
array.push(document.data().name);
});
}
}).catch(function(error) {
console.log("Error getting documents:", error);
});
var prodpic = array[0]; // Array is not filled because in output always "undefined"
I do want to work with the img-links in prodpic in my later program. I hope my problem is clear and anyone can help me to find my mistake.