簡體   English   中英

如何將 firestore 集合中的字段值與輸入字段中的數據進行比較?

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

我是 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>

正如這里提到的那樣,這樣做的方法是使用不同的結構,其中登錄名(在您的情況下我認為是電子郵件)作為文檔的 ID,這樣您就可以查詢 ID 為“adeel@”的文檔雅虎網”。

這將使對 firestore 的查詢更加高效,因為您每次登錄只需要閱讀一個文檔,並且它還將強制該字段的唯一性。

另外對於密碼,不建議以純文本形式存儲,所以我建議您存儲密碼的 hash,並與 hash 進行比較。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM