如何查询Firestore数组中的值

时间:2018-09-07 05:43:50

标签: swift firebase google-cloud-firestore

每个Firebase Firestore文档中,要查询数组包含某个值的集合,请执行以下操作:

citiesRef.whereField("regions", arrayContains: "west_coast")

仅当我尝试在Swift 4中编写该代码时,才会出现以下错误:

Argument labels '(_:, arrayContains:)' do not match any available overloads

查看可用的重载会产生以下内容:

Query whereField(field: String, isEqualTo: Any)
Query whereField(path: FieldPath, isEqualTo: Any)
Query whereField(field: String, isLessThan: Any)
Query whereField(path: FieldPath, isLessThan: Any)
Query whereField(field: String, isGreaterThan: Any)
Query whereField(path: FieldPath, isGreaterThan: Any)
Query whereField(field: String, isLessThanOrEqualTo: Any)
Query whereField(path: FieldPath, isLessThanOrEqualTo: Any)
Query whereField(field: String, isGreaterThanOrEqualTo: Any)
Query whereField(path: FieldPath, isGreaterThanOrEqualTo: Any)

关于数组或包含的内容不存在。文档过时了吗?我想念什么? Docs found here

我的Podfile:

 platform :ios, '9.0'

target 'Appname' do
use_frameworks!

# Pods for Appname

pod ‘Firebase/Core’
pod ‘Firebase/Auth’
pod 'Firebase/Database'
pod 'Firebase/Firestore'
pod 'Firebase/Storage'
pod 'Firebase/Invites'
pod 'SwiftGifOrigin', '~> 1.6'
pod 'Kingfisher', '~> 4.0'
pod 'AudioKit', '~> 4.0'
pod 'KSTokenView', '~> 4.0'
pod 'ReachabilitySwift'
pod 'ZFTokenField'
pod 'SlackTextViewController'
pod 'RealmSwift'

target 'AppnameTests' do
 inherit! :search_paths
 # Pods for testing
end

target 'AppnameUITests' do
 inherit! :search_paths
 # Pods for testing
end

end

1 个答案:

答案 0 :(得分:3)

arrayContains支持已在Firestore pod的5.5.0中发布。确保您使用的是该版本或更高版本。 Read the release notes here.