简体   繁体   English

如何手动将文档字段添加到本地 QueryDocumentSnapshot 列表

[英]How can i manually add document-fields into local QueryDocumentSnapshot List

i have the following list我有以下列表

List <QueryDocumentSnapshot>  globalVideosUrls = [] ;

for example if we use the following例如,如果我们使用以下

 FirebaseFirestore.instance.collection('users')
            .limit(1).get().then((value){
             globalVideosUrls.add(value)
        });

it will add as expected它会按预期添加

but what if i want to manually add the following data into globalVideosUrls但是如果我想手动将以下数据添加到globalVideosUrls

document id文档编号

00dcb026-3163-4ca0-859e

fields字段

 'videoType':'peace'

 'url':'url'


.

globalVideosUrls .add(????) globalVideosUrls (???)

You have to replace the type "QueryDocumentSnapshot" with QuerySnapshot and then you will get multiple docs and with there data also try this If any questions then ask.您必须将类型“QueryDocumentSnapshot”替换为 QuerySnapshot,然后您将获得多个文档,并且那里的数据也试试这个如果有任何问题,请询问。 thanks.谢谢。

List<QuerySnapshot> globalVideosUrls = [];
List<String> videoUrlList = [];
await FirebaseFirestore.instance
    .collection('users')
    .get()
    .then((value) {
  globalVideosUrls.add(value);
});
globalVideosUrls.forEach((element) {
  element.docs.forEach((docELe) {
    print("data:- ${docELe.data()}");
    Map map = docELe.data() as Map;
    videoUrlList.add(map['url']);
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何定义帖子列表的最后一个文档? - how can i define the last document of the list of posts? Flutter + Cloud firestore + Closures:为什么我可以将文档打印到控制台,但不能添加到列表中? - Flutter + Cloud firestore + Closures: Why can I print the document to the console, but not add to a list? 如何在不指定文档 ID 和使用 Firestore 自动 ID 生成器的情况下添加到 Firestore? - How can I add to Firestore without specifying a document ID and utilising Firestores auto ID generator? 如何手动触发 Kubernetes 计划作业? - How can I trigger a Kubernetes Scheduled Job manually? 如何在 orderBy 之后获取特定索引处的文档 - How can I get a document at a specific index after orderBy 如何从 Firestore 获取文档 ID 列表 - How do I get a list of document ID’s from Firestore 如何遍历 Flutter 中的 Firestore 文档中的字段? - How to iterate through fields in a Firestore Document in Flutter? Flutter Firestore:将数据列表添加到 Firestore 文档 - Flutter Firestore : Add a List of Data to Firestore Document 如何使用帮助文档 ID 更新 Cloud firestore 文档字段? - How can i Update Cloud firestore document Field with the help DocumentID? 如何轻松地将我的 GQLQuery 的日期字段格式化为另一个时区? - How can I easily format the date fields of my GQLQuery to another Timezone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM