[英]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.