简体   繁体   English

我在 Firestore 数据库文档中添加了一个地图作为字段,里面有一个子字段,但我的 RecyclerView 遇到了问题

[英]I added a map as a field in my Firestore DB document with a sub field inside, and I am facing issues to my RecyclerView

I am facing issues with my RecyclerView in displaying my app's candidates when I include the added map field in my query.当我在查询中包含添加的地图字段时,我的 RecyclerView 在显示我的应用程序的候选项时遇到了问题。 I also have created an index for this query but still, nothing comes out of my RecyclerView.我还为这个查询创建了一个索引,但我的 RecyclerView 仍然没有任何内容。

This is the UPDATED query code.这是更新的查询代码。 If there is something wrong with the coding, please do notify me.如果编码有问题,请通知我。

FirebaseUser user = mAuth.getCurrentUser();
    String voterID = user.getUid();
    Query query = notebookRef.whereEqualTo("registrationStatus", "Accepted").whereEqualTo( voterID, false).orderBy("candidateFullName", Query.Direction.ASCENDING);

    FirestoreRecyclerOptions<VoterCandidateItem> options = new FirestoreRecyclerOptions.Builder<VoterCandidateItem>()
            .setQuery(query, VoterCandidateItem.class)
            .build();

    adapter = new VoterCandidateAdapter(options);

    recyclerView = findViewById(R.id.candidateList);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    recyclerView.setItemAnimator(null);

This is the UPDATED screenshot of Firestore DB:这是 Firestore DB 的更新截图: 在此处输入图片说明

And this is the UPDATED screenshot of the index:这是索引的更新截图: 在此处输入图片说明

The following query:以下查询:

Query query = notebookRef
        .whereEqualTo("registrationStatus", "Accepted")
        .whereEqualTo(voterID, false)
        .orderBy("candidateFullName", Query.Direction.ASCENDING);

Requires an index , otherwise, it will not work.需要一个 索引,否则将无法工作。 If you are using Android Studio, you'll find in the logcat an error message that looks like this:如果您使用的是 Android Studio,您会在 logcat 中找到如下所示的错误消息:

FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/...

The required query can be created either directly in the Firebase Console , or by clicking on that link.所需的查询可以直接在Firebase 控制台中创建,也可以通过单击该链接来创建。 If the click doesn't work, simply copy and paste the URL into a web browser and your index will be created automatically for you.如果点击不起作用,只需将 URL 复制并粘贴到 Web 浏览器中,就会自动为您创建索引。

If you choose the console, remember to set:如果选择控制台,记得设置:

Collection: Candidates Fields: registrationStatus ascending and voterID: ascending集合:候选人字段:注册状态升序选民ID:升序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Firestore DB 文档中地图字段的子字段中检索值? - How to retrieve a value from a sub-field of a map field in a document in Firestore DB? 我在将日期字段加载到 elasticsearch 时遇到问题。 它不是正确的日期 - I am having issues with my Date field while loading it into elasticsearch. Its not coming as proper Date 我的 HackerRank 解决方案正面临超时 - I am facing timeout for my solution for a HackerRank 我的嵌套 DTO 字段收到 null 响应 - I am getting null response for my nested DTO field 如何在 queryDocumentSnapshot Firestore 中查询文档字段 - How to query a document field inside of queryDocumentSnapshot Firestore 如何将一组自定义对象添加到Firestore文档字段? - How do I add an array of custom objects to a Firestore document field? 我在Java中的扫描仪类中遇到问题 - I am Facing issues in Scanner Class in java 我正在尝试将MongoDB的数据逐字段获取到我的Java代码中 - I am trying to get data from MongoDB field by field into my Java Code 运行我的应用程序时,我在 Flutter 中遇到问题 - I am facing issue in Flutter while run my application 运行我的Java代码时,我遇到此错误-&gt; - when running my java code i am facing this error ->
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM