未获取创建消防仓库索引的链接



在我的flutter应用程序中,我正在运行一个类似于以下的firestore查询:

final userDoc = await _firestore.userDocument();
final name = nameStr.toUpperCase();
yield* userDoc.firestore
.collectionGroup('persons')
.where(
'name',
isGreaterThanOrEqualTo: name,
isLessThan: name.substring(0, name.length - 1) +
String.fromCharCode(
name.codeUnitAt(name.length - 1) + 1),
)
.snapshots()
.map(
(snapshot) => right<Failure, List<Person>>(
snapshot.docs
.map((doc) => Dto.fromFirestore(doc).toDomain())
.toList(),
),
)
.onErrorReturnWith((e) {
if (e is PlatformException && e.message.contains('PERMISSION_DENIED')) {
return ...;
} else {
print(e.toString());
return ...;
}
});

它显示以下错误:

I/flutter(27416(:[cloud_firestore/failed precondition]操作被拒绝,因为系统未处于执行操作所需的状态。如果执行查询,请确保已通过Firebase控制台对其进行了索引。

可能是因为where,我需要在控制台中添加索引,所以在错误消息中,我希望有一个url来添加索引,但没有得到。我尝试了adb logcat,甚至没有。

在集合组查询的文档中,您将在底部找到:

"在使用集合组查询之前,必须创建一个支持集合组查询的索引。您可以通过错误消息、控制台或Firebase CLI创建索引。

对于web和移动SDK,还必须创建允许集合组查询的规则">

因此,您需要为集合组创建安全规则,然后,如果无法通过adb logcat获得错误消息,则需要通过Firebase控制台或Firebase CLI手动创建索引。

您需要分离where语句。

.collectionGroup('persons')
.where(
'name',
isGreaterThanOrEqualTo: name)
.where('name', isLessThan: name.substring(0, name.length - 1) +
String.fromCharCode(
name.codeUnitAt(name.length - 1) + 1),
)

最新更新