【问题标题】:Check if email exists in user list using AngularFire2使用 AngularFire2 检查用户列表中是否存在电子邮件
【发布时间】:2017-06-16 12:57:05
【问题描述】:

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

我使用此功能并在 10 分钟后将 50MB 的数据下载到我的 PC 中,我得到了存在的响应。有什么方法可以让我不到 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;
}

【问题讨论】:

  • 您将x 传递给equalTo,它可能应该是equalTo: email。但是,如果 x 是要过滤的值,那么该性能似乎很不寻常。您是否为email 添加了索引?如果没有,JavaScript 控制台中将显示警告。如果这不是问题,有什么办法可以设置一个 jsbin 来为您重现这种性能?
  • Frank,我是 George hatouts,这是我的第二个帐户。是的,在 x 内我传递了我从输入中获取的电子邮件,我想在提交表单之前检查该电子邮件是否存在于数据库中,如果该电子邮件存在我想通知用户,该电子邮件存在
  • 我会给你一个例子,它不是我的问题的答案,但描述问题给我 2 分钟
  • 非常感谢

标签: firebase firebase-realtime-database angularfire2


【解决方案1】:

我的天啊,我发现https://stackoverflow.com/users/209103/frank-van-puffelen 的问题是关于 index 的问题,当我查看我的 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 
    }

  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2018-07-20
    相关资源
    最近更新 更多