query from firebase realtime database
As shown in the documentation on reading data, you can use get
to get the data at a path or for a query.
const myOffersRef = query(ref(db, 'allOffers/'), orderByChild('uid'), equalTo(user.uid));
get(myOffersRef).then((snapshot) => {
snapshot.forEach((child) => {
console.log(child.key, child.val().uid);
});
}).catch((error) => {
console.error(error);
});
Note that I also changed startAt
to equalTo
, as you likely only want the nodes that match the UID, not the slide of nodes starting from the first match (which is what startAt
does).
The forEach
is needed since a query can potentially have multiple results, so the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result.
Use query data from Firebase Realtime DB as input for another function
The on
method keeps an open listener to the event that can be called repeatedly, so it doesn't return a promise (since a promise can only resolve once). So the await ref.orderByChild....on('child_added'...
in your code doesn't do anything, which probably explains the problem.
To properly solve this problem, use once('value', ...
and don't combine await
and callbacks.
async function queryandgeturls() {
// make the query to the firebase realtimeDB
const results = await ref.orderByChild('timestamp_start').startAt(timestamp1).endAt(timestamp2).once('value');
results.forEach((snapshot) => {
lista.push(snapshot.val().name);
});
...
Related Topics
How to Use Data Binding and Kotlin in Android Studio 3.0.0
Debugging Android Ndk Native Apps
How Do Cursorloader Automatically Updates the View Even If the App Is Inactive
How to Add Parameters to API (Http Post) Using Okhttp Library in Android
Kitkat Kills: Not Allowed to Load Local Resource: File:///Android_Asset/Webkit/Android-Weberror.Png
How to Reverse the Direction of Marquee of a Textview
How to Get the Key from the Value in Firebase
How to Open Navigation Drawer with No Actionbar, Open with Just a Button
Android Notification with Buttons on It
Page Scroll When Soft Keyboard Popped Up
Install App via Usb: the Device Is Temporarily Restricted
How to Copy Selected Files from Android with Adb Pull
Creating a Product Sdk: How to Add a Native Lib (.So) and a Jar with the Sdk I am Creating