0

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.The underlined field is what I would like to access the document by

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?

David
  • 769
  • 1
  • 6
  • 28

1 Answers1

1

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.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • So I can access all documents or one document in a collection but not a group specific ones? – David Jul 03 '19 at 00:02
  • Using a single query, that is correct. If you need multiple specific documents, you will have to `get()` each one individually. – Doug Stevenson Jul 03 '19 at 00:10