Can a query be constructed using a list of strings

2019-08-18 07:52发布

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?

1条回答
可以哭但决不认输i
2楼-- · 2019-08-18 08:52

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.

查看更多
登录 后发表回答