简体   繁体   中英

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

document id

00dcb026-3163-4ca0-859e

fields

 'videoType':'peace'

 'url':'url'


.

globalVideosUrls .add(????)

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. 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']);
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM