Needed Details
I am using Dialogflow fulfillment for my project along with Firebase realtime database. My database has a structure:
Let me first tell you about the structure of the database. It has got a list of ATMs(automated teller machine) with its full address and other needful information. I need to fetch all the ATMs with a given value of Pin
number, and the given value of Pin
number will come from an API response. This Pin number is nothing but the Zip Code for that ATM. So obviously, with a Pin
number, there can be many ATMs.
My problem
Below is the code I am using to make an API call and Firebase database querying with received Pin value as the response from API.
var ref = db.ref("atms/");
var response = await axios.get('some URL'); //API call
var zipcodes = response.data.search_results; // Array of Pin values
console.log(zipcodes[2].postal_code); //This prints a Pin value 721304, which confirms successful response from API
ref.orderByChild("Pin").equalTo(zipcodes[2].postal_code).on("child_added", function(snapshot) { //this line is the problem
console.log(snapshot.val());
});
But the above code with equalTo(zipcodes[2].postal_code)
does not give any response. But when I replace it with equalTo(721304)
, it does give an expected response. To emphasize, both equalTo(zipcodes[2].postal_code)
and equalTo(721304)
are necessarily same.
I need to use this equalTo(zipcodes[2].postal_code)
only because I will be running a loop over this query, which is because of the need to query many, many Pin
at once.
Could you please help me understand what is wrong here and how do I implement what I am trying to do here? Please let me know in case of any follow-up questions.