首页 > 解决方案 > 无效的查询。“in”过滤器支持值数组中最多 10 个元素

问题描述

当数组超过 10(大小)时,查询 whereIn 在 firestore 中不起作用。

无效的查询。“in”过滤器支持值数组中最多 10 个元素。

这是我的代码

  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);

任何人请帮助在 Firestore WhereIn 查询中获取 10 多个数组字段

标签: javaandroidgoogle-cloud-firestore

解决方案


如错误消息所述,您最多可以将 10 个值传递给whereIn. 如果需要超过 10 个值,则需要执行多个查询并将结果合并到应用程序代码中。


推荐阅读