我正在尝试在一个字段上使用子句WhereEqualTo在Android Firebase Cloud Firestore中获取集合中的一个文档,但是我不知道为什么有时候在数据库中有相同数据时会得到空结果。
有时结果为空。当我删除whereEqualTo子句时,我得到了所有集合。
这是我的要求
public static Task<QuerySnapshot> getUserByEmail() {
String email = "mireille@sombux.com";
return UserHelper.getUsersCollection()
.whereEqualTo("email", email)
.get();
}
这是我的用户类
public abstract class User {
private long id;
private String email;
private Date lastLogin;
private Date birthday;
private String country;
private String codcountry;
private String formation;
private String drink;
private String about;
public User() {}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getLastLogin() {
return lastLogin;
}
public void setLastLogin(Date lastLogin) {
this.lastLogin = lastLogin;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCodcountry() {
return codcountry;
}
public void setCodcountry(String codcountry) {
this.codcountry = codcountry;
}
public String getFormation() {
return formation;
}
public void setFormation(String formation) {
this.formation = formation;
}
public String getDrink() {
return drink;
}
public void setDrink(String drink) {
this.drink = drink;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
这是我的数据
我这样使用它
UserHelper.getUserByEmail().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
final User remoteUser = document.toObject(User.class);
if (remoteUser != null) {
Toast.makeText(context, "Find", Toast.LENGTH_SHORT).show();
// do something
}
return;
}
Toast.makeText(context, "Not find", Toast.LENGTH_SHORT).show();
}
}
});