android - 无法从 Firestore 读取数据
问题描述
我正在尝试使用电话号码注册用户,我的目标是用户只能使用一个电话号码注册意味着没有重复,所以在注册时我正在 Firestore 中读取,如果输入的号码在数据库中可用,则显示错误,否则它将注册。但是在读取数据 Firestore 时,什么也没有返回。它也没有显示任何错误吐司。相同的功能在其他应用程序中运行良好。
这是代码
mFireStore = FirebaseFirestore.getInstance()
mFireStore.collection("USERS")
.whereEqualTo("Number", number.text.toString())
.get()
.addOnSuccessListener { documents ->
for (document in documents) {
if( document != null ){
Log.i("Null","Document Not null")
Toast.makeText(this,"Phone Number Already Exist",Toast.LENGTH_SHORT).show()
}else{
val OTP = Intent(this@MainActivity,OTPActivity::class.java)
OTP.putExtra("Name",NAME.text.toString())
OTP.putExtra("Number","+"+92+number.text.toString())
OTP.putExtra("Age",age.text.toString())
OTP.putExtra("District",district.text.toString())
startActivity(OTP)
}
}
}
.addOnFailureListener { exception ->
Toast.makeText(this,exception.toString(),Toast.LENGTH_SHORT).show()
}
这是我的安全规则
match /{document=**} {
allow read, write: if true;
}
解决方案
如果要查询 Firestore 数据库,需要先创建索引。通过这个链接,它会达到你的目的,希望!
推荐阅读
- c# - 使用 Directory.GetDirectories(Path) 在 WPF C# 中填充 DataGrid
- javascript - 以编程方式创建 Vue 3 组件实例
- javascript - 如何在不出现 401 错误的情况下访问 msal graph api
- javascript - 将数组数组转换为对象
- mysql - 直接在mysql中插入后计算值
- excel - 将下拉列表过滤为键入,而不使用 ActiveX for desktop Excel
- python - IndexError:索引 29 超出轴 0 的范围,大小为 29
- javascript - 为什么我不能对二维数组进行适当的迭代?
- selenium - Robotframework:找不到名称为“打开浏览器”的关键字
- ios - 返回视图控制器时大标题变为小标题