简体   繁体   English

如何将 firestore 集合中的字段值与输入字段中的数据进行比较?

[英]How do I compare the field value in a collection in firestore with the data from the input fields?

I'm new to firebase and I don't know how to compare the data in the input fields with the data in firestore.我是 firebase 的新手,我不知道如何将输入字段中的数据与 Firestore 中的数据进行比较。 I've searched the firestore documentation for this but can't seem to find it.我已经为此搜索了 firestore 文档,但似乎找不到。 Would really appreciate the help !非常感谢您的帮助!

This is the image of the data:这是数据的图像:

https://i.stack.imgur.com/zAlEG.jpg 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>

As mentioned here the way to do this is to have a different structure, where the login (in your case I think it would be the email) as the id of the document, This way you can query for the document with ID "adeel@yahoo.com".正如这里提到的那样,这样做的方法是使用不同的结构,其中登录名(在您的情况下我认为是电子邮件)作为文档的 ID,这样您就可以查询 ID 为“adeel@”的文档雅虎网”。

This will make the queries to firestore a lot more efficient, as you will only need to read one document per login, and it will also enforce the unicity of this field.这将使对 firestore 的查询更加高效,因为您每次登录只需要阅读一个文档,并且它还将强制该字段的唯一性。

Additionally for the password it is not recommended to store them in plain text, so I would recommend you to store a hash of the password, and compare with the hash.另外对于密码,不建议以纯文本形式存储,所以我建议您存储密码的 hash,并与 hash 进行比较。

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

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