【发布时间】:2019-01-22 09:17:13
【问题描述】:
我有一组用户,我想从数据库中查询所有用户并将它们显示在 RecyclerView 中,除了一个 我的。这是我的数据库架构:
users [collection]
- uid [document]
- uid: "fR5bih7SysccRu2Gu9990TeSSyg2"
- username: "John"
- age: 22
- //other users
如何像这样查询数据库:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
Query q = db.collection("users").whereNotEqualTo("uid", uid);
所以我需要将此查询对象传递给FirestoreRecyclerOptions 对象,以便显示RecyclerView 中的所有其他用户。
这甚至可能吗?如果没有,我该如何解决这个问题?谢谢!
编辑:
options = new FirestoreRecyclerOptions.Builder<UserModel>()
.setQuery(query, new SnapshotParser<UserModel>() {
@NonNull
@Override
public UserModel parseSnapshot(@NonNull DocumentSnapshot snapshot) {
UserModel userModel = documentSnapshot.toObject(UserModel.class);
if (!userModel.getUid().equals(uid)) {
return userModel;
} else {
return new UserModel();
}
}
}).build();
【问题讨论】:
-
你执行并查看结果了吗?
-
@UmarHussain 我无法执行此操作,因为没有
whereNotEqualTo,这就是为什么我要问我该如何解决这个问题。你有什么想法吗? -
好吧,firestore 与我认为的方法相同,但缺少此方法。
-
如果只是一项的问题,为什么不进行客户端过滤呢?
-
@SuhaylSH 您能否就如何实现这一目标发表答案?谢谢!
标签: java android firebase kotlin google-cloud-firestore