[英]how to get a list of users from firebase
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.我能够将数据库 output 到控制台。 I would like to output only the email addresses of users.
我想 output 只有用户的 email 地址。
JSON File JSON 文件
{
"users": {
"2Le5WxOGnWWrkshsEqjeSIq527O2": {
"email": "q5@gmail.com",
"password": "qweqwe"
},
"2jn1YmI9twce3ylEP8wiu5QhUDf1": {
"email": "55@gmail.com",
"password": "qweqwe"
},
To retrieve all users and output only their email addresses:要检索所有用户和 output 仅他们的 email 地址:
get(child(dbRef, `users/` )).then((snapshot) => {
snapshot.forEach((child) => {
console.log(child.val().email);
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.