Firebase实时数据库上的字段值哈希相等查询

huangapple go评论48阅读模式
英文:

Firebase RT Database Query on field value hash equality

问题

我有一个Firebase实时数据库,其中用户的电子邮件存储在子字段中,例如:

/users/00Vho6lTQke46IqpRv0D5dw6DXs2/email -> user@email.com

我想要进行一次查询,根据电子邮件地址的MD5哈希获取用户。例如,MD5('user@email.com') -> 'b58c6f14d292556214bd64909bcdb118'

我没有用户的电子邮件地址,我只有MD5哈希。是否可以使用MD5函数来将电子邮件字段转换为MD5并进行查询?

英文:

I have a Firebase Realtime Database with users and the email is stored in a child field, for example:

/users/00Vho6lTQke46IqpRv0D5dw6DXs2/email -> user@email.com

I want to query once and get a user based on the MD5 hash of the email address. For example, MD5('user@email.com') -> 'b58c6f14d292556214bd64909bcdb118'.

I don't have the email address of the user, I only have the MD5 hash. Is it possible to query using an MD5 function to transform the email field to MD5 and query on that?

答案1

得分: 1

不可以,除非您将MD5保存为数据库中的字段。如果这样做,您将能够使用MD5进行查询。您的模式应如下所示:

db
|
--- users
     |
     --- 00Vho6lTQke46IqpRv0D5dw6DXs2
           |
           --- email: "user@email.com"
           |
           --- md5: "b58c6f14d292556214bd64909bcdb118"

查询应如下所示:

val query = db.child("users").orderByChild("md5").equalTo("b58c6f14d292556214bd64909bcdb118");
英文:

> Is it possible to query using an MD5 function to transform the email field to MD5 and query on that?

No, unless you save the MD5 as a field inside the database. If you do that, you'll be able to query using the MD5. Your schema should look like this:

db
|
--- users
     |
     --- 00Vho6lTQke46IqpRv0D5dw6DXs2
           |
           --- email: "user@email.com"
           |
           --- md5: "b58c6f14d292556214bd64909bcdb118"

And the query should look like this:

val query = db.child("users").orderByChild("md5").equalTo("b58c6f14d292556214bd64909bcdb118");

huangapple
  • 本文由 发表于 2023年6月1日 22:15:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定