简体   繁体   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

Actually i'm storing map object under my firestore document with some ids of users which i block like this. 实际上我正在我的firestore文档下存储地图对象和一些用户ID,我这样阻止。 点击下面的链接查看图片

i have all members ids which i block in my social app and i need to get all those members document using firestore query but query doesnot work if arraylist has more than one index.but when i have only one id the query works perfect. 我有我在社交应用程序中阻止的所有成员ID,我需要使用firestore查询获取所有这些成员文档,但如果arraylist有多个索引,则查询不起作用。但是当我只有一个id时,查询工作完美。 here is the code 这是代码

 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");
                    }
                }
            });
}
}

query doesnot work if arraylist has more than one index.but when i have only one id the query works perfect 如果arraylist有多个索引,则查询不起作用。但是当我只有一个id时,查询工作正常

try this 尝试这个

// 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.

相关问题 如何从 Firestore Android 中的集合中获取文档列表 - How to get list of documents from a collection in Firestore Android Android Studio-如何从Firestore的子集合中获取文档? - Android Studio - How do I get documents from a sub-collection in Firestore? Java,Firestore - 在 android 工作室中使用 arraylist 的文档 ID 从 Firestore 获取多个文档 - Java, Firestore - Get multiple documents from firestore using an arraylist of document ids in android studio Android Firestore 查询:获取集合中的文档数 - Android Firestore Query : get the number of documents within a collection 如何查询 Firestore 子集合并获取 spacyfyi 文档 ID? - How to query on Firestore sub collection and get spacyfyi document id? 如何使用Android在Cloud Firestore中查询特定文档后的集合? - How to query a Collection after a specific Document in Cloud Firestore with Android? 如何在 Firestore 中获取特定集合? - How to get specific collection in Firestore? 如何从Firestore中的集合中检索所有文档? - How to retrieve all documents from a collection in Firestore? Java Firestore Android 在查询中使用 arraylist 以显示来自关注用户的帖子 - Java Firestore Android use an arraylist in a query to show posts from followed users 如何使用Java Play中的MorphiaQuery从集合中获取所有_id值并将其存储在arraylist中 - How to get all _id values from a collection and store them in arraylist using MorphiaQuery in Java Play
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM