Firebase,获得具有特定价值的孩子的直接父母 [英] Firebase, get immediate parent of a child with specific value

查看:53
本文介绍了Firebase,获得具有特定价值的孩子的直接父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带Firebase后端的ios应用程序.当用户注册时,将在firebase中创建用户节点,该节点下有诸如电子邮件,名称,头像等不同的子代.我正在做的是在用户节点中搜索一些电子邮件,如果在某个节点中找到该电子邮件,我要获取其父密钥,即-Ksdd23d2djhsdgjhs.查看图片:

I am working on an ios app with firebase backend. As users register, user node is created in firebase under which there are different children like email, name, avatar etc. What I am doing is that I am searching for some email in user nodes and if I find that email in some node, I want to get its parent key i.e -Ksdd23d2djhsdgjhs. See the image:

如果电子邮件与我的电子邮件匹配,我想用上箭头获取值.

I want to get the value with upper arrow if the email matches with the one I have.

我有一个电子邮件地址,我正在搜索用户节点中的所有子级,然后进一步在内部检查以将电子邮件与我的电子邮件进行比较.如果电子邮件匹配,我希望得到其父节点,如图中的Dn2LUAwdolg ......

I have an email address and I am searching through all of the children in user node and then further check inside the to compare the email with the one I have. If email matches, I want to get its parent node like in the image it is Dn2LUAwdolg..... .

我可以在用户节点下获得第一个节点.假定图中所示的节点Dn2LU ..处于某个未知位置,并且如果电子邮件子值与我正在比较的电子邮件子值匹配,则我必须搜索所有用户以获取其名称.

I can get the first node under user node. Assume that the node Dn2LU.. shown in picture is at some unknown position and I have to search all users to get its name if it's email child value matches with the one I am comparing it with.

希望现在很清楚

推荐答案

我认为您正在寻找的内容记录在这里: https://firebase.google.com/docs/reference/js /firebase.database.Reference#equalTo

I think what you are looking for is documented here: https://firebase.google.com/docs/reference/js/firebase.database.Reference#equalTo

我不是IOS开发人员,但是我这里是一个JS示例:

I am no IOS developer, but I here is a JS example:

// Find all users which match the child node email.
var ref = firebase.database().ref('user');
ref.orderByChild('email').equalTo('wal@aol.com').on("value", function(snapshot) {
  snapshot.forEach((function(child) { console.log(child.key) }); 
});

快照包含整个节点,但是snapshot.key将返回节点密钥(在您的示例中:Dn2LUAwdolg ...)

Tthe snapshot contains the whole node, but snapshot.key will return the node key (in your example: Dn2LUAwdolg...)

这篇关于Firebase,获得具有特定价值的孩子的直接父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆