Android Firebase多级子查询
如何获取用户包含特定Uid的所有聊天Android Firebase多级子查询,android,firebase,firebase-realtime-database,firebaseui,Android,Firebase,Firebase Realtime Database,Firebaseui,如何获取用户包含特定Uid的所有聊天 Query sItemQuery = mDatabase.getReference().child("chats").limitToLast(200); FirebaseRecyclerOptions<ChatMetaData> options = new FirebaseRecyclerOptions.Builder<ChatMetaData>()
Query sItemQuery = mDatabase.getReference().child("chats").limitToLast(200);
FirebaseRecyclerOptions<ChatMetaData> options =
new FirebaseRecyclerOptions.Builder<ChatMetaData>()
.setQuery(sItemQuery, ChatMetaData.class)
.setLifecycleOwner(this)
.build();
querysitemquery=mDatabase.getReference().child(“chats”).limitToLast(200);
FirebaseRecyclerOptions选项=
新的FirebaseRecyclerOptions.Builder()
.setQuery(sItemQuery,chatmatadata.class)
.setLifecycleOwner(此)
.build();
您不能像这样跨多个级别进行查询。看 因此,虽然您当前的数据结构使在聊天中查找当前用户变得很容易,但却无法为用户查找当前聊天 为此,您需要添加一个额外的数据结构。比如:
user_chats: {
uid1: {
chatid1: true,
chatid2: true
}
uid2: {
chatid2: true,
chatid3: true
}
}
使用此附加结构,您可以通过阅读/user\u chats/$uid
轻松找到当前用户的聊天记录
另见:
- 您不能像这样跨多个级别进行查询。看
因此,虽然您当前的数据结构使在聊天中查找当前用户变得很容易,但却无法为用户查找当前聊天
为此,您需要添加一个额外的数据结构。比如:
user_chats: {
uid1: {
chatid1: true,
chatid2: true
}
uid2: {
chatid2: true,
chatid3: true
}
}
使用此附加结构,您可以通过阅读/user\u chats/$uid
轻松找到当前用户的聊天记录
另见: