Flutter - FireBase复合查询-不显示任何结果

ohtdti5x  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(138)

我正在尝试创建复合查询。我总是得到“无可用数据”。这很奇怪,因为有数据与我的查询匹配。请您帮助我找出我缺少的数据吗?谢谢

Future myQuery () async{

    final currentQuery = FirebaseFirestore.instance
        .collection('Users')
        .doc(FirebaseAuth.instance.currentUser!.uid)
        .collection('allTasks');

    Query nameQuery = currentQuery.where('status', isEqualTo: 'Inbox');
    Query nameValorQuery = nameQuery.where('important', isEqualTo: 'False');
    
    final snapshot = await nameValorQuery.firestore.collection('allTasks').get(); //('users/$userId').get();

    if (snapshot.docs.isNotEmpty) {
      print(snapshot.docs.first);
    } else {
      print (snapshot.docs.length);
      print('No data available.');
    }
mkshixfv

mkshixfv1#

我修改了你的代码,应该能用,希望能帮上忙。

Future myQuery () async{
    final uid = FirebaseAuth.instance.currentUser!.uid;
    final path = 'Users/$uid/allTasks';

    final currentQuery = FirebaseFirestore.instance.collection(path);
    Query nameQuery = currentQuery.where('status', isEqualTo: 'Inbox');
    Query nameValorQuery = nameQuery.where('important', isEqualTo: 'False');
    
    final snapshot = await nameValorQuery.get();

    final data = snapshot.docs;
    if(data.isNotEmpty){
      for(var i =0; i < data.length; i++){
        print(data[i].data());
      }
    }
    }

相关问题