Retrieve nested structured database of firebase

How can I retrieve from nested database. The database structure is attached


firebase.database().ref('/requests').child(firstId).child(secondId).on('value', (snapshot) => {
    // it should return the recipient and sender under the 'secondId'


  • firstId = W8MHvHBcNeU…
  • secondId = -Kz2bt9HqQh…

firstId and secondId is not know …how can i get what’s the firstid

The code I gave you shows how to retrieve nested data with firebase, so it answers your initial question.
What you really want to do is probably more complex, so you will need to explain exactly what you want to achieve (also from a user point of view).

I gave the structure of database from where i need to extract the value of sender and recipient. Basically I am trying to make a chat app and for this purpose “requests” table is for saving the requests send to the user. First id is the recipient id shows the request send to this user. Now i want to get the sender and recipient id to check that the request is sent to this user and now don’t send the request again to this user

Was there ever a solution found for this, where the firstId and secondId are unknown?