Kumar
Kumar

Reputation: 979

Firebase-firestore querying the selected field values using Android FirestoreRecyclerAdapter not working

firestore screenshoti am trying to query the selected document from firestore collections based on field value. single WHERE condition is working fine. but multiple documents not able to fetch from Firestore using single query.

Code:

Query query = db.collection("users").whereEqualTo("email","[email protected]",);//here how to add multiple emails as a input.


FirestoreRecyclerOptions<User> response = new FirestoreRecyclerOptions.Builder<User>()
                .setQuery(query, User.class)
                .build();

        firestoreRecyclerAdapter = new FirestoreRecyclerAdapter<User, FriendsHolder>(response) {
            @Override
            public void onBindViewHolder(FriendsHolder holder, int position, User model)
            {
                    holder.nameView.setText(model.getDisplayName());
                    holder.statusView.setText(model.getStatus());
                       
            }

            @Override
            public FriendsHolder onCreateViewHolder(ViewGroup group, int i) {
                View view = LayoutInflater.from(group.getContext()).inflate(R.layout.users_view_item, group, false);

                return new FriendsHolder(view);
            }

            @Override
            public void onError(FirebaseFirestoreException e) {
                Log.e("error", e.getMessage());
            }
        };


        firestoreRecyclerAdapter.notifyDataSetChanged();
        recyclerViewfriendList.setAdapter(firestoreRecyclerAdapter);
        firestoreRecyclerAdapter.startListening();
    }

kindly help me thanks in advance.

Upvotes: 0

Views: 397

Answers (1)

Muthu Thavamani
Muthu Thavamani

Reputation: 1405

how to add multiple emails as a input.

I think you are looking for in condition

Query query = db.collection("users").whereIn("email", Arrays.asList("[email protected]", "[email protected]"));
  • in query returns documents where the given field matches any of the comparison values

Upvotes: 1

Related Questions