Home > Software design >  Firebase RTDB - Get document ID?
Firebase RTDB - Get document ID?

Time:05-18

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

CodePudding user response:

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.

  • Related