gpt4 book ai didi

firebase - 无法从StreamBuilder(Flutter)查询子集合

转载 作者:行者123 更新时间:2023-12-03 03:35:18 25 4
gpt4 key购买 nike

我正在尝试从StreamBuilder中查询一个子集合,但是该查询返回了零个文档,尽管该子集合中有一个文档。查询父集合将返回正确数量的文档,并且已验证传递给子集合的文档ID。我想念什么?

StreamBuilder<QuerySnapshot>(
stream: _firestore
.collection('books')
.document(documentID)
.collection('enquiries')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text('You have not received any enquiries yet!');
} else {
final numberOfDocs = snapshot.data.documents.length;
print(numberOfDocs); // HELP HERE! returns 0, although a document exists in the subcollection
print(documentID); // returns the expected document ID
...

Firestore Subcollection:

documentID passed to the .document() method

最佳答案

对于Firestore中的初学者来说,这非常令人困惑,但是从您提供的屏幕截图来看,子集合中似乎实际上没有任何文档。

如果文档ID的名称为斜体,则表示该文档具有子集合,但文档本身没有。

当您创建文档的子集合然后在以后删除该文档时,会发生这种情况。

确保在books / kOhVCohNlbQWkGem06RF /查询中创建一些文档,您应该一切顺利!

关于firebase - 无法从StreamBuilder(Flutter)查询子集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61469267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com