首页 > 解决方案 > Firestore“array-contains-any”不起作用

问题描述

我正在尝试在 iOS (Swift) 上使用 Firestore 查询:

db.collection(FS_PICS)
            //.whereField("category", arrayContains: "Animals")
            .whereField("category", arrayContains: ["Animals", "Dogs"])
            .getDocuments() { (querySnapshot, err) in
                if let err = err {
                    print("Error getting documents: \(err)")
                } else {
                    for document in querySnapshot!.documents {
                        print("\(document.documentID) => \(document.data())")
                    }
                }
        }

它不返回任何结果

// doesn't work
.whereField("category", arrayContains: ["Animals", "Dogs"])

或与

// doesn't work
.whereField("category", in: ["Animals", "Dogs"])

但我有 8 个结果:

// It works!!
.whereField("category", arrayContains: "Animals")

它不像 OR 甚至不像 AND 那样工作,因为它也不起作用:

// It works!!
.whereField("category", arrayContains: ["Animals"])

那么这个函数的想法是什么,我应该怎么做才能得到 OR ?

标签: iosswiftfirebasegoogle-cloud-firestore

解决方案


问题出在文档中的代码示例中。它应该是arrayContainsAny 在此处输入图像描述

对于其他语言是正确的:

在此处输入图像描述


推荐阅读