首页 > 解决方案 > 未为集合组中的 arrayContains 生成 Firestore 索引 URL?

问题描述

snapshot1使用和单个集合并snapshot2使用集合组

final snapshot1 = await FirebaseFirestore.instance
    .collection('users')
    .doc('115309562732908784445')
    .collection('user_activities')
    .where('userGroupIDs', arrayContains: 'IIPwobuR3YLrOoLH3TeS')
    .get();
final snapshot2 = await FirebaseFirestore.instance
    .collectionGroup('user_activities')
    .where('userGroupIDs', arrayContains: 'IIPwobuR3YLrOoLH3TeS')
    .get();

snapshot1snapshot2通过throws生成罚款

Exception has occurred.
FirebaseException ([cloud_firestore/failed-precondition] Operation was rejected because the system is 
not in a state required for the operation's execution. If performing a query, ensure it has been 
indexed via the Firebase console.)

但我没有得到自动生成的 URL。上述消息与 VSCode 编辑器窗口重叠。我在调试控制台和 Firestore 日志中都没有看到任何 URL 消息。

我的查询有问题吗?或者有时您必须手动创建它们?

标签: google-cloud-firestore

解决方案


我手动构建了索引,它运行良好。跟随Todd 的博客很简单。作为测试,我删除了几个现有的索引,调试器正确地给了我一个重建的 URL。不知道为什么它不喜欢这个。


推荐阅读