我想在Android firestore
中获取根集合的文档字段我在firestore中的数据库结构是
collection
documents-->root fields
collection
documents-->fields
现在我想获取根字段。如何在android firestore中做到这一点?
firestore.collection("Players").orderBy("deptName").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
//model class
Example example=document.toObject(Example.class);
exampleList.add(example);
}
Toast.makeText(getActivity(), ""+exampleList, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), ""+task.getException(), Toast.LENGTH_SHORT).show();
}
}
});
答案 0 :(得分:0)
firestore.collection("Players").orderBy("deptName").get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
//model class
Example example=document.toObject(Example.class);
example.setDocID(document.getId());
exampleList.add(example);
}
Toast.makeText(getActivity(), ""+exampleList, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), ""+task.getException(), Toast.LENGTH_SHORT).show();
}
}
});
https://firebase.google.com/docs/firestore/query-data/get-data#java_2