【问题标题】:Firestore flutter complex queryFirestore 颤振复杂查询
【发布时间】:2021-05-19 09:24:33
【问题描述】:

我想在我的颤振应用中执行搜索,我使用的查询是这样的:

searchUser = FirebaseFirestore.instance
            .collection('User')
            .where("name", isGreaterThanOrEqualTo: mySearchController.text)
            .where("name", isLessThan: limit);

现在,这给了我结果,但它显示了所有文档,现在我想再执行 1 个这样的“位置”:

.where("friends", arrayContains: globals.patientPhoneNum)

所以我的最终查询看起来像:

searchUser = FirebaseFirestore.instance
            .collection('User')
            .where("friends", arrayContains: globals.patientPhoneNum)
            .where("name", isGreaterThanOrEqualTo: mySearchController.text)
            .where("name", isLessThan: limit);

但是现在,这给了我错误:

(22.1.2) [Firestore]: Listen for Query(target=Query(User where friends array_contains # com.google.firestore.v1.Value@ff357562
W/Firestore(16941): integer_value: 0
W/Firestore(16941): string_value: "+919869787899" and name >= # com.google.firestore.v1.Value@9deca
W/Firestore(16941): integer_value: 0
W/Firestore(16941): string_value: "Ra" and name < # com.google.firestore.v1.Value@9deff
W/Firestore(16941): integer_value: 0
W/Firestore(16941): string_value: "Rb" order by name, __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/acm2021-1d053/firestore/indexes?create_composite=Ckpwcm9qZWN0cy9hY20yMDIxLTFkMDUzL2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9Vc2VyL2luZGV4ZXMvXxABGgsKB2ZyaWVuZHMYARoICgRuYW1lEAEaDAoIX19uYW1lX18QAQ, cause=null}

Firestore:

【问题讨论】:

标签: flutter google-cloud-firestore


【解决方案1】:

您必须按照 Firebase 提供的说明进行操作

  1. 打开出现在命令行的链接(this)
  2. 点击创建索引按钮(右下角的蓝色按钮)
  3. 等待索引请求的状态从 Building 更改为 Enabled(此步骤可能需要 4-5 分钟)
  4. 查询现在应该可以正常工作了

【讨论】:

  • 谢谢 :) 我是新手,不知道感谢它
猜你喜欢
  • 2019-07-18
  • 2019-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-13
  • 2021-10-22
  • 2021-11-25
  • 2021-10-06
相关资源
最近更新 更多