0
function getUsersEmail() {
  const dbRef = ref(getDatabase());
  get(child(dbRef, `users/`  )).then((snapshot) => {
    if (snapshot.exists()) {
      console.table(snapshot.val());
    } else {
      console.log("No data available");
    }
  }).catch((error) => {
    console.error(error);
  });
}

I was able to output the database to the console. I would like to output only the email addresses of users.

JSON File

 {
"users": {
"2Le5WxOGnWWrkshsEqjeSIq527O2": {
  "email": "q5@gmail.com",
  "password": "qweqwe"
},
"2jn1YmI9twce3ylEP8wiu5QhUDf1": {
  "email": "55@gmail.com",
  "password": "qweqwe"
},
Wyse
  • 33
  • 5
  • Please edit your question to show what the data from `users` looks like (as text, no screenshots please). You can get this by clicking the "Export JSON" link in the overflow menu (⠇) on your [Firebase Database console](https://console.firebase.google.com/project/_/database/data). – Frank van Puffelen Sep 03 '22 at 19:41
  • i added Json, pls watch ) – Wyse Sep 04 '22 at 11:10
  • https://stackoverflow.com/questions/43159916/how-to-filter-data-in-firebase – gapsf Sep 04 '22 at 11:37
  • 2017 so late... – Wyse Sep 04 '22 at 12:13

1 Answers1

1

To retrieve all users and output only their email addresses:

get(child(dbRef, `users/`  )).then((snapshot) => {
  snapshot.forEach((child) => {
    console.log(child.val().email);
  })
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you so much, otherwise I have almost implemented it through collections. What are the differences Realtime database and firestore database ?? – Wyse Sep 04 '22 at 15:20
  • https://stackoverflow.com/questions/46549766/whats-the-difference-between-cloud-firestore-and-the-firebase-realtime-database – Frank van Puffelen Sep 04 '22 at 16:09