使用AngularFire2检查用户列表中是否存在电子邮件

时间:2017-06-16 12:57:05

标签: firebase firebase-realtime-database angularfire2

我想检查一下Firebase数据库中是否存在email = someemail@gmai.com的用户。

我使用此功能,并在10分钟后在我的PC上下载50MB数据,我得到了一个响应。我可以通过任何方式获得不到5秒的时间,我不想等待10分钟。

PHP中的

就像

SELECT FROM ALL USERS WERE EMAIL = 'george@gmail.com'

这是数据库:

"users" : {

    user: {
      "email" : "george@gmail.com",
      "custom_id" : 534253,
      "description" : "some small description"
    },

    1754: {
      "email" : "natassa@gmail.com", <---- i want to find if this email from 5000 users exist in database and if exist i want to return true
      "custom_id" : 110571,   
      "description" : "some small description"
    },

    1755: {
      "email" : "george@gmail.com",
      "custom_id" : dsgfsdfds,
      "description" : "some small description"
    },

  }

此功能在10分钟后给我回复:

check_if_email_exist(email: string) {

    this.users = this.db.list('/user', { query: {
      orderByChild: 'email',
      equalTo: x,
      limitToLast: 10,
    }} ) as FirebaseListObservable<Product[]>;

    console.log(this.users);

    return this.users;
}

1 个答案:

答案 0 :(得分:0)

OMG我发现问题thanx https://stackoverflow.com/users/209103/frank-van-puffelen说了一些关于索引的内容,当我查看我的Chrome控制台时,我发现有关索引的警告,当我查看数据库时规则我理解缺少什么

我在数据库规则

中添加了这个
{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",

    "needs": {
      ".read": "true",
      ".write": "auth != null",
      ".indexOn": "name"
    },

    "brands": {
      ".read": "true",
      ".write": "auth != null",
      ".indexOn": "name"
    },

    "products": {
      ".read": "true",
      ".write": "auth != null",
      ".indexOn": "custom_id"   <========== This line you want 
    }

  }
}
相关问题