![](/img/trans.png)
[英]How to query through multiple documents in a collection (Firestore/Flutter)
[英]Is this how to iterate through documents on a Firestore collection in flutter?
在下面的代碼中,我嘗試使用 flutter 和 dart 檢索 Firestore 中的集合中的所有文檔。 這是最好的方法嗎?
Query () async {
QuerySnapshot snapshot = await Firestore.instance.collection("collectionName").getDocuments();
snapshot.documents.forEach((document){
if(document.exists){
print('Documents exist');
}
else {
print('document does not exist');
}
});
是的,這是從集合中檢索文檔的方法。 此外,默認情況下,firestore 會嘗試離線緩存數據並從那里加載,這有時會阻止它從服務器獲取數據,即使服務器有不同的數據。 為了防止您可以在 getDocuments 方法中添加源標志, .getDocuments(source: Source.server);
像這樣。 如果您想以不同的方式構建您的應用程序,那么您可以這樣做,但是您仍然必須調用相同的方法來從 firestore 檢索數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.