如何从Firebase获取查询? [英] How can I get query from firebase?

查看:39
本文介绍了如何从Firebase获取查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firebase中有一个名为video的集合,然后我保存了每个id的视频.在每个视频ID中,我都保存了一些字段,因此我现在正尝试访问它们,这是我正在尝试的方式.目前,我获得了所有用户的ID,但不知道如何完成

Im have a collection in firebase named videos and then I got saved the videos id each . And in every video id I saved some field so now im trying to get access to them Heres how im trying . At the moment I got the ids of all user but don't how to finish it

List listOfIds = [];
  
    var idofotheruser = await FirebaseFirestore.instance
        .collection('videos')
        .get();
  
     idofotheruser.docs.forEach((element) {
      listOfIds.add(element.id);
    });
  
  QuerySnapshot qn = await FirebaseFirestore.instance
        .collection('videos')
      .where('id', whereIn: listOfIds)
        .get();

 setState(() {
      _allResults = qn.docs;
      print(qn.docs);
    });

 

通过查询im获取每个视频内的id字段.但是我想要的实际上是获取hashtag1和hashtags2和hashtag3字段,这是我的收藏集,因此您可以更好地了解如您所见,我有3个主题标签,我尝试将所有主题标签都放在一个列表中.我需要将结果保存在名为_allResults

With the query im getting the id field inside each video . But what I want is actually getting the hashtag1 and hashtags2 and hashtag3 field heres my collection so you can understand a bit better So as you can see I have a 3 hashtags and I try to get all of them in one list . I need to save the result in a list called _allResults

希望任何人都可以帮助

推荐答案

尝试使用

qn.documents.forEach((doc){
 /*doc.data should contain what your looking for */
});

这篇关于如何从Firebase获取查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆