I've been struggling with creating a firebase query all day!
The below query returns the data as an array from my Firebase realtime database:
exports.getCountry = () => {
return database
.ref("/countries")
.once("value")
.then(data => data.val());
};
This returns the below from the database in the format Array of Objects,
[
{"id":1, "country":"singapore", "population":15000000},
{"id":2, "country":"hongkong", "population":12000000},
{"id":2, "country":"vietnam", "population":2250000}
]
However I want to query the database to just return one record, something along the lines of
exports.getCountry = () => {
return database
.ref("/countries")
.where('id'===1)
.once("value")
.then(data => data.val());
};
would return a single line from my database:
{"id":1, "country":"singapore", "population":15000000}
however I can't get this to work! It should be simple, but I can't get it to play ball!