繁体   English   中英

如果我使用Query在“Android”中拥有用户ID arraylist,如何从“Firestore”集合中获取特定的文档列表

[英]How to get specific list of documents from “Firestore” collection if i have users ID arraylist in “Android” using Query

实际上我正在我的firestore文档下存储地图对象和一些用户ID,我这样阻止。 点击下面的链接查看图片

我有我在社交应用程序中阻止的所有成员ID,我需要使用firestore查询获取所有这些成员文档,但如果arraylist有多个索引,则查询不起作用。但是当我只有一个id时,查询工作完美。 这是代码

 private ArrayList<String> blocks =new ArrayList<>();
    if (logedInMember != null){
        blocks = logedInMember.getBlocks();
        if (!blocks.isEmpty()){
            Query query;
            CollectionReference collection = firestore.collection(Constants.MEMBERS);
            query  = collection;

            for (int i = 0 ; i< blocks.size(); i++){
                Log.d("block member ID :", blocks.get(i) );
                // now its time to query all these ids
                String id = blocks.get(i);
                if (!id.isEmpty()){
                    query = query.whereEqualTo(Constants.ID,id);
                }
            }

            query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()){


                        for (QueryDocumentSnapshot document : task.getResult()) {
                            Member member = document.toObject(Member.class);
                            Log.d("Member Id :", member.getId());
                            Log.d("Member Name :", member.getName());

                        }
                    }else {
                       // loader.dismissProgress();
                        Log.d("error : ","fail to load query");
                    }
                }
            });
}
}

如果arraylist有多个索引,则查询不起作用。但是当我只有一个id时,查询工作正常

尝试这个

// RETRIEVING ALL Queries
Query allQueries = firebaseFirestore
                    .collection("yourcollection")                    
                    .orderBy("timestamp", Query.Direction.DESCENDING)
                    .limit(5);

            allQueries.addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {


                    for (DocumentChange doc : documentSnapshots.getDocumentChanges()) {

                        if (doc.getType() == DocumentChange.Type.ADDED) {
                            // get all ids
                            String postId = doc.getDocument().getId();
                            contentProfileDashboard = doc.getDocument().toObject(ContentProfileDashboard.class);                                                             
                                                     contentListDashboard.add(contentProfileDashboard);                         

                            // fire the event           
                            adapterProfileDashboard.notifyDataSetChanged();
                        }
                    }


                }
            });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM