[英]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.