我有一个Firebase项目,其结构如下
CollectionReference adminList;
adminList = mFirestore.collection("AdminList");
Map<String,Object> k = new HashMap<>();
k.put("order",order);
k.put("status","New Order");
k.put("hotel_name",username.getText().toString());
k.put("user_id",mUid);
k.put("time", "Select Time");
//adminList.document(order).set(k);
adminList.document(mUid).collection("User").document(order).set(k);
可以有多个用户使用UserId . 我必须在列表中检索它 .
为此,我使用了以下代码 .
@Override
protected void onStart() {
super.onStart();
mFirestore.collection("AdminList").getParent().collection("Users").addSnapshotListener(MainActivity.this, new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
orderList.clear();
assert queryDocumentSnapshots != null;
List<OrderList> types = queryDocumentSnapshots.toObjects(OrderList.class);
orderList.addAll(types);
adapter = new AdminListAdapter(MainActivity.this,orderList);
recyclerView.setAdapter(adapter);
}
});
}
但我需要一种方法来访问子集合及其文档,以便我可以在recyclerview中检索列表 .
1 回答
这样做: -