【问题标题】:How do I compare the field value in a collection in firestore with the data from the input fields?如何将 firestore 集合中的字段值与输入字段中的数据进行比较?
【发布时间】:2020-04-30 18:21:53
【问题描述】:

我是 firebase 新手,不知道如何将输入字段中的数据与 firestore 中的数据进行比较。我已经为此搜索了 firestore 文档,但似乎找不到。非常感谢您的帮助!

这是数据的图像:

https://i.stack.imgur.com/zAlEG.jpg

  db.collection("kaprixlogin")
.add({
  users: {
    email: "adeel@yahoo.com",
    password: "nova",
  },
})
.then(function (docRef) {
  console.log("Document written with ID: ", docRef.id);
})
.catch(function (error) {
  console.error("Error adding document: ", error);
});

db.collection("kaprixlogin")
  .get()
  .then((snap) => {
    snap.forEach((doc) => {
      console.log(doc.data());
      console.log(doc.id);
    });
 });
<form method="POST" action="">
    <div class="form-label-group">
        <input type="email" id="useremail" name="mail" class="form-control" placeholder="Email" required autofocus>
        <label for="useremail">Email address</label>
    </div>
    
    <div class="form-label-group">
        <input type="password" id="inputPassword" name="pass" class="form-control" placeholder="Password" required>
        <label for="inputPassword">Password</label>
    </div>
</form>

【问题讨论】:

  • 您的用例是什么?你打算用这个登录吗?
  • 是的,我想比较一下 login_id 是否已经在存储中

标签: javascript firebase google-cloud-firestore


【解决方案1】:

正如here 提到的那样,这样做的方法是使用不同的结构,其中登录名(在您的情况下我认为是电子邮件)作为文档的 id,这样您就可以查询文档ID 为“adeel@yahoo.com”。

这将使查询到 firestore 的效率更高,因为您每次登录只需阅读一个文档,并且还将强制该字段的唯一性。

另外对于密码,不建议以纯文本形式存储,所以我建议你存储密码的哈希值,并与哈希值进行比较。

【讨论】:

  • 感谢反馈会试一试。
猜你喜欢
  • 1970-01-01
  • 2023-02-02
  • 2019-07-16
  • 2017-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多