【问题标题】:Flutter APP crashes when opening page with query使用查询打开页面时 Flutter APP 崩溃
【发布时间】:2021-11-26 18:07:53
【问题描述】:

大家好,在尝试打开带有查询的页面时,应用程序开始一次又一次地终止。我没有获得创建索引或类似内容的链接,它只是在 iOS 和 android 上终止,我收到以下错误。

这是代码

idofotheruser = await FirebaseFirestore.instance
            .collection('meinprofilsettings')
            .doc(user)
            .collection('BlockedUser')
            .limit(10)
            .get();

        idofotheruser.docs.forEach((element) {
          listOfIds.add(element.id);
        });
        if (idofotheruser.docs.length > 0) {
          print("test123");
          print(widget.hashtag);
          try {
            querySnapshots = await FirebaseFirestore.instance
                .collection('videos')
                .where('uid', whereNotIn: listOfIds)
                .where('Hashtagsforallvideos', arrayContains: widget.hashtag)
                .orderBy("uid")
                .limit(13)
                .get();
An error occurred while parsing query arguments, this is most likely an error with this SDK.
E/FLTFirestoreMsgCodec(16249): java.lang.IllegalArgumentException: Invalid Query. You cannot use 'not_in' filters with 'array_contains' filters.


我也试过这样

await FirebaseFirestore.instance
    .collection('videos')
    .where('Hashtagsforallvideos', arrayContains: widget.hashtag)
    .limit(15)
    .get()
    .then((value) => {
          if (value.docs.isNotEmpty)
            {
              value.docs.forEach((doc) {
                if (doc.data()['uid']) {
                } else {}
                // doc.data() is never undefined for query doc snapshots
              }),
            }

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    错误很明显:

    您不能将“not_in”过滤器与“array_contains”过滤器一起使用。

    您不能在查询中组合这两个子句:

    .where('uid', whereNotIn: listOfIds)
    .where('Hashtagsforallvideos', arrayContains: widget.hashtag)
    

    来自query limitatioms上的文档:

    每个查询最多可以使用一个数组包含子句。您不能将 array-contains 与 array-contains-any 结合起来。

    每个查询最多可以使用一个 in、not-in 或 array-contains-any 子句。不能在同一个查询中组合 in 、 not-in 和 array-contains-any 。

    如果您需要同时按这两个条件进行过滤,则必须在查询中执行一个,在应用程序代码中执行另一个。

    【讨论】:

    • 好的,但是我该如何组合这两个类?
    • 你不能。您必须在查询中执行其中一个,在您的应用程序代码中执行另一个。
    • 嘿,我用代码更新了我的问题,也许你可以检查我不确定我是否做得对。那么如何检查 uid 是否包含来自 idoftheotherusers 用户的任何 docid?
    • if (!listOfIds.contains(doc.data()['uid'])?
    猜你喜欢
    • 2020-08-02
    • 1970-01-01
    • 2019-06-28
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2020-12-06
    • 2011-07-02
    相关资源
    最近更新 更多