简体   繁体   English

我想用子值检索 firebase 数据库数据

[英]i want to retrieve firebase database data with the child value

query.once("value") .then(function(snapshot) {
      var childData = snapshot.val().user_name;
      var childData2 = snapshot.val().user_id;
 document.writeln(childData);
 document.writeln("\n");
 document.writeln(childData2);
});

this is the code i used for retrieving firebase database value using parent value what changes should i make in this code for retrieving the parent values using the child value这是我用于使用父值检索 firebase 数据库值的代码 我应该在此代码中进行哪些更改以使用子值检索父值

这是我的数据库参考

I would like to retrieve user_name with help of password.我想在密码的帮助下检索 user_name。 And also i want it to be work for other records in the users.而且我还希望它适用于用户中的其他记录。

If the password is "2110" you can retrieve the user with:如果密码是"2110"您可以通过以下方式检索用户:

var passwordToLookFor = "2110";
var ref = firebase.database().ref("users");
var query = ref.orderByChild("password").equalTo(passwordToLookFor);
query.once(function(snapshot) {
  snapshot.forEach(function(child) { // loop over the results
    console.log(child.key);
    console.log(child.val().user_name);
  });
});

As Doug commented, please take a moment to read the Firebase documentation on ordering and querying , as it will save you many questions going forward.正如 Doug 评论的那样,请花点时间阅读有关订购和查询的 Firebase 文档,因为它将为您节省很多问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用javaScript在Firebase数据库中检索嵌套的子值? - How to retrieve nested child value in Firebase database using javaScript? 如何使用名称检索Firebase数据库子节点但不推送ID - How to i retrieve the firebase database child node with Name but not push id 在Firebase中检索子值[web] - retrieve child value in firebase [web] 如何通过Web应用程序中的值从Firebase数据库检索数据? - How can I retrieve data from firebase database by its value in Web App? 当子级Firebase和javascript发生更改时,我需要键值 - i want key value when there is change in it's child firebase and javascript 如何使用Firebase云功能从Firebase数据库检索子节点的键值? - How to retrieve key value of child node from firebase database using firebase cloud function? 我想从 Firebase 检索数据到 HTML 文本框中,然后更新 Firebase 中的数据 - I want to retrieve data from Firebase into an HTML textbox, then update the data in Firebase 如何使用 firebase 数据库存储和检索数组值? - How can i stored and retrieve an array value using firebase database? 我无法使用异步管道从Firebase数据库检索数据 - I cannot retrieve data from firebase database using async pipe 如何从我的 firebase 数据库中检索数据? - How can I retrieve data from my firebase database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM