Firebase RTDB – Get document ID?

how can i retrieve document IDs in a useEffect using firebase realtime database?

This works great but however i need every single document id aswell.
enter image description here

enter image description here

>Solution :

This is how you can get keys from array in RTDB:

onValue(dbRef, (snapshot) => {
  snapshot.forEach((childSnapshot) => {
    const childKey = childSnapshot.key;
    const childData = childSnapshot.val();
    // ...
  });
}, {
  onlyOnce: true
});

You need to get to childSnapshots using forEach or for loop.

Leave a Reply