来自Firebase Firestore的Streambuilder,具有高级过滤功能 [英] Streambuilder from firebase firestore with advanced filtering

查看:80
本文介绍了来自Firebase Firestore的Streambuilder,具有高级过滤功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于扑朔迷离的Firebase依赖关系的新版本,有新的过滤器如isNotEqualTo,arrayContains,arrayContainsAny,whereIn等.

Based on new version of firebase dependencies in flutter, there is new filters such like isNotEqualTo, arrayContains, arrayContainsAny, whereIn and so on.

我尝试用一​​些过滤器创建streambuilder,我想获取符合这些条件的文档.

I try to create streambuilder with some filters, I want to get documents that matches these conditions.

  1. "uid"字段值不等于当前uid.(isNotEqualTo)
  2. 学校"字段值isEqualTo当前用户学校.(isEqualTo)
  3. 随机"字段值isGreaterThanOrEqualTo应用程序生成它的随机数(isGreaterThanOrEqualTo)

stream:fireStore.collection(USERS_COLLECTION).where(UID_FIELD,isNotEqualTo:me.uid).where(SCHOOL_FIELD,isEqualTo:me.school).where(RANDOM_FIELD,isGreaterThanOrEqualTo:随机).limit(10).snapshots(),

stream: fireStore.collection(USERS_COLLECTION).where(UID_FIELD, isNotEqualTo: me.uid).where(SCHOOL_FIELD, isEqualTo: me.school).where(RANDOM_FIELD, isGreaterThanOrEqualTo: random).limit(10).snapshots(),

条件1(isNotEqualTo)对我不起作用,但是条件2和3很好用,当我添加过滤器1时,向我显示错误.

Condition 1 (isNotEqualTo) does not work with me, but 2 and 3 it's working fine, when I add the filter 1 there is error showing to me.

所有不等式(<,< =,>或> =)的过滤器都必须位于同一领域.但是您在'FieldPath([uid])'上有不等式过滤器,并且"FieldPath([random])".'package:cloud_firestore/src/query.dart':断言失败:486行pos 18:'hasInequality == field'

All where filters with an inequality (<, <=, >, or >=) must be on the same field. But you have inequality filters on 'FieldPath([uid])' and 'FieldPath([random])'. 'package:cloud_firestore/src/query.dart': Failed assertion: line 486 pos 18: 'hasInequality == field'

推荐答案

那是Firestore的限制 https://firebase.google.com/docs/firestore/query-data/查询

That is a Firestore-Limitation https://firebase.google.com/docs/firestore/query-data/queries

请注意!=查询的以下限制:

Note the following limitations for != queries:

只有给定字段存在的文档才可以匹配查询.您不能在复合查询中组合not-in和!=.在复合查询中,范围(<,< =,>,> =)和!=比较必须全部过滤在同一字段上.

Only documents where the given field exists can match the query. You can't combine not-in and != in a compound query. In a compound query, range (<, <=, >, >=) and != comparisons must all filter on the same field.

因此,您可以在uid上使用!=进行过滤,也可以在Random上使用> =进行过滤.您不能在同一查询中同时执行这两项.

So you can either filter using != on the uid OR you can filter using >= on Random. You cannot do both in the same query.

我建议您在不使用UID的情况下进行过滤,并在收到快照后让您的存储库在以后过滤掉UID.

I'd recommend filtering without the UID and let your repository filter out the UID later, once you've received the snapshots.

这篇关于来自Firebase Firestore的Streambuilder,具有高级过滤功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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