简体   繁体   English

Firebase firestore 查询不会过滤数据,即使在 flutter 中使用 where 时也是如此

[英]Firebase firestore queries are not filtering data, even when using where in flutter

I'm trying to use where in a Firebase firestore query in my flutter application but it is showing all the data in the collection without filtering it., here is my code:我试图在我的 flutter 应用程序中的 Firebase firestore 查询中使用where但它显示了集合中的所有数据而不过滤它。这是我的代码:

  Widget buildingMessages() {
    print('message room id $roomID'); //The correct id is being printed here
    var theMessages = FirebaseFirestore.instance.collection('messages');
    theMessages.where('room_id',isEqualTo: roomID).orderBy('created', descending: true);
    return StreamBuilder<QuerySnapshot>(
      stream: theMessages.snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          return Text('Something went wrong');
        }

        return new ListView(
          children: snapshot.data.docs.map((DocumentSnapshot document) {
//....

The problem is in stream: theMessages.snapshots() .问题出在stream: theMessages.snapshots()中。 You are referencing the theMessages .您正在引用theMessages and you are not using your where clause.而且您没有使用 where 子句。 extends it with your where clause.用你的 where 子句扩展它。 like喜欢

stream: theMessages.snapshots().where(
                  'room_id',isEqualTo: roomID).orderBy('created', descending: true);

Edit: Or initialize it as编辑:或将其初始化为

var theMessages = FirebaseFirestore.instance.collection('messages').
            where('room_id',isEqualTo: roomID).orderBy('created', descending: true);

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

相关问题 在 flutter 中使用 orderBy() 时,firebase firestore 没有值 - no value from firebase firestore when using orderBy() in flutter 请求数据时以及未使用Firebase身份验证的情况下,如何编写Firebase Firestore的安全规则? - How to write security rules for firebase firestore when request data and in case where we have not used firebase authentication? 使用带有 flutter 的 Firestore 时出现问题 - problem when using firestore with flutter 如何使用 excel 或 google 电子表格或 CSV 使用 excel 导入 firebase firestore 数据库中的批量数据 - How to import bulk data in firebase firestore database from excel or google spreadsheet or CSV using flutter 在查询 Firestore 中过滤数据? - Filtering data in a query Firestore? Flutter 使用 Cloud Firestore 和 Firebase Auth 存储用户数据 - Flutter store users data with Cloud Firestore and Firebase Auth 使用 Firestore 获取数据时出现 Flutter 错误 - Flutter error while using Firestore to fetch data 如何使用 Firebase Firestore 获取查询数据? - How to get query data using Firebase Firestore? 即使参考检索数据,Firebase查询在Android上也不起作用 - Firebase queries not working on Android even though the reference retrieves data 如何使用flutter在Firebase云Firestore中添加多个节点 - how to add multiple nodes in Firebase cloud Firestore using flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM