I wish to filter documents based on a list which contains userId's these userId's are fields in the documents I wish to access. this question is similar but instead of a list of document references I have a list of field items.
Currently all I have is a display of all the documents in the collection:
Query posts = db.collection("posts");
FirestoreRecyclerOptions<Post> options = new FirestoreRecyclerOptions.Builder<Post>()
.setQuery(posts, Post.class)
.build();
adapter = new FirestoreRecyclerAdapter<Post, PostViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull PostViewHolder postViewHolder, int position, @NonNull Post post) {
postViewHolder.setPost(post);
}
@NonNull
@Override
public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_view_layout, parent, false);
return new PostViewHolder(view);
}
};
recyclerView.setAdapter(adapter);
I want the output to be all posts with a field userId that is contained in the List.
In other words, I know that I can query all documents with a specific field but can I query all documents that fit a a list of fields?
It's currently not possible to make one query return all documents that exist in an existing list. This means you will not be able to use FirestoreRecyclerAdapter to populate your RecyclerView, since it's only capable of taking a single Query object. Instead, you will have to make a query for each one of the documents you want to display, collect the results in memory, and use a different type of adapter to populate the view.