[英]How to Delete all documents in collection in Firestore with Flutter
[英]How to get all data of documents with unique names in Flutter Firestore in same listview
我有一個具有唯一文檔名稱的集合 ( reg_schools ) ( Liebenberg Primary School, St Michaels Primary School )。 然后那些唯一命名的文檔有集合( school_news )和隨機文檔 ID 名稱也有數據,我想知道我是否可以為 Liebenberg 小學和 Michaels 小學收集所有這些數據 'school_news ' 並擁有它在同一個列表視圖中。 請看我的圖片。
目前,如果我在 Streambuilder 中輸入唯一的文檔名稱,我只知道獲取 school_news 數據。
Container(
height: 500,
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('reg_schools')
.doc('Libenberg Primary School')
.collection('school_news')
.orderBy('created', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: LinearProgressIndicator(),
);
} else
return ListView(
children: snapshot.data!.docs.map((doc) {
return Padding(
所以我的問題是,如何在同一個列表視圖中獲取 Liebenberg 小學和 St Michaels 小學的所有 school_news 數據?
更新
根據給出的答案創建索引。 並且能夠獲取所有 school_news 收集數據
我能否對返回的內容進行一些過濾,例如:
FirebaseFirestore.instance
.collectionGroup('school_news')
.where('name', arrayContainsAny: test)
.snapshots(),
然后我將有一個列表,如:
List userSelections = ['Liebenberg', 'St Michaels' , 'School C' ];
您可以使用集合組查詢來查詢所有同名子集合中的文檔,將整個文檔集視為一個單元。 為此使用collectionGroup() 。
FirebaseFirestore.instance
.collectionGroup('school_news')
.orderBy('created', descending: true)
.snapshots()
無法從該查詢中排除任何路徑。 您必須獲取具有給定名稱的所有子集合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.