简体   繁体   English

如何使用 email 作为您的 firebase 数据的 ID 并根据它检索数据

[英]How to use email as a ID of your firebase data and retrieve data according to it

I am trying to make a app where user can login with email and password.我正在尝试制作一个用户可以使用 email 和密码登录的应用程序。 But i have saved its credentials with the ID (user ID) how can I retrieve data according to my email not my user ID.但我已经用 ID(用户 ID)保存了它的凭据,我如何根据我的 email 而不是我的用户 ID 检索数据。

火力地堡数据库

When I try to retrieve data with the "email" in my query it is showing the error当我尝试在查询中使用“电子邮件”检索数据时,它显示错误

Query check=db_refer.orderByChild("email").equalTo(emails);
        check.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if(snapshot.exists()){
                    String db_pass=snapshot.child(emails).child("pass").getValue(String.class);
                    if(db_pass.equals(passs)){
                        Toast.makeText(SignIn.this, "SIGNED IN", Toast.LENGTH_SHORT).show();
                    }
                    else{                                  Toast.makeText(SignIn.this, db_pass+" and "+passs, Toast.LENGTH_SHORT).show();
                        Toast.makeText(SignIn.this, "NOT SIGNED IN", Toast.LENGTH_SHORT).show();

                    }
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {
            }
        });
    }
});

This is the error message which my compiler is showing:这是我的编译器显示的错误消息:

W/PersistentConnection: pc_0 - Using an unspecified index. W/PersistentConnection: pc_0 - 使用未指定的索引。 Your data will be downloaded and filtered on the client.您的数据将在客户端下载和过滤。 Consider adding '".indexOn": "email"' at Workers to your security and Firebase Database rules for better performance考虑在 Workers 处添加“.indexOn”: “email”' 以提高安全性和 Firebase 数据库规则以获得更好的性能

The error message says that the filtering of the data is currently being done inside the Android application, instead of on the server.错误消息说数据的过滤当前正在 Android 应用程序内部完成,而不是在服务器上完成。 This is highly unscalable, so you'll want to fix that by adding an index in your database rules:这是高度不可扩展的,因此您需要通过在数据库规则中添加索引来解决此问题:

{
  "rules": {
    ...
    "Workers": {
      ".indexOn": "email"
    }
  }
}

I recommend searching for any error messages that you get going forward, as this error came up before .我建议搜索您收到的任何错误消息,因为此错误之前出现过

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM