1

The Query whereIn not works in firestore when the array has more than 10(size).

Invalid Query. 'in' filters support a maximum of 10 elements in the value array.

this is my code

  Query query = postRef.whereIn("id", postIdList).orderBy("timestamp", Query.Direction.ASCENDING);

        PagedList.Config config = new PagedList.Config.Builder()
                .setInitialLoadSizeHint(10)
                .setPageSize(3)
                .build();

        FirestorePagingOptions<Posts> options =  new FirestorePagingOptions.Builder<Posts>()
                .setLifecycleOwner(this)
                .setQuery(query,config,Posts.class)
                .build();


        firestorePagingAdapter = new FirestorePagingAdapter<Posts, PostPagingAdapter>(options) {


            @NonNull
            @Override
            public PostPagingAdapter onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = getLayoutInflater().inflate(R.layout.post_items,parent,false);
                return new PostPagingAdapter(view);
            }

            @Override
            protected void onBindViewHolder(@NonNull PostPagingAdapter holder, int position, @NonNull Posts model) {
                holder.bind(model);
            }

            @Override
            protected void onError(@NonNull Exception e) {
                super.onError(e);
                Log.e(TAG, "onError: " + e.getMessage());
            }

            @Override
            protected void onLoadingStateChanged(@NonNull LoadingState state) {
                super.onLoadingStateChanged(state);

                switch (state) {
                    case LOADING_INITIAL:
                    case LOADING_MORE:
                        mSwipeRefreshLayout.setRefreshing(true);
                        break;

                    case LOADED:

                    case FINISHED:
                        mSwipeRefreshLayout.setRefreshing(false);
                        break;

                    case ERROR:
                        Toast.makeText(getApplicationContext(), "Slow internet connection", Toast.LENGTH_SHORT).show();

                        mSwipeRefreshLayout.setRefreshing(false);
                        break;
                }

            }
        };


        bookmarks_recycler_view.setAdapter(firestorePagingAdapter);

Anybody pls help to get more than 10 arrayFields in Firestore WhereIn query

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51

1 Answers1

0

As the error message says, you can pass no more than 10 values to whereIn. If you need more than 10 values, you'll need to execute multiple queries and merge the results in your application code.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • We're not a code writing service here. If you're having trouble executing two queries and merging the results, edit your question to show what you tried. – Frank van Puffelen Apr 16 '21 at 22:28
  • Check out [this](https://stackoverflow.com/a/50132229/8303912) answer to see how to merge to queries, it is important to note `whenAllSuccess()` so that all queries are fetched before attempting to merge. – Hipster Cat May 31 '21 at 18:09