Description
Description
After switching from Firebase emulators (Firestore, Auth, Storage) to Firebase production, Firestore queries using whereField consistently fail to fetch documents from the production database, while the same queries succeed when using the emulator.
Specifically, the query that filters the households collection using arrayContains on the users field works perfectly in emulator mode but returns empty results or fails entirely when running against Firebase production.
Reproducing the issue
Steps:
Configure Firebase Firestore, Auth, and Storage to use emulators.
Successfully fetch documents from the households collection using a whereField query with arrayContains.
Remove emulator settings and deploy the app connected to Firebase production.
Attempt to fetch documents using the same whereField query in production.
Minimal reproducible example:
@MainActor
func fetchHouseholds(for user: User) async -> [Household] {
var households: [Household] = []
do {
let householdRef = Firestore.firestore().collection("households")
.whereField("users", arrayContains: user.documentRef)
let householdDocuments = try await householdRef.getDocuments()
households = householdDocuments.documents.compactMap { document in
do {
return try document.data(as: Household.self)
} catch {
print("Failed to parse household document: \(error)")
return nil
}
}
return households
} catch {
print("Error fetching households: \(error.localizedDescription)")
return []
}
}
Firebase SDK Version
10.9
Xcode Version
15.3
Installation Method
Swift Package Manager
Firebase Product(s)
Firestore
Auth
Storage
Targeted Platforms
iOS
Firebase SDK Version
10.9
Xcode Version
15.3
Installation Method
Swift Package Manager
Firebase Product(s)
Firestore
Targeted Platforms
iOS, N/A
Relevant Log Output
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved
snippet
{
"originHash" : "9e805dd553b0e8652d0c79c3fd88edc2024f61f4826bf842d8b1e8c2556c4c2c",
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "bbe8b69694d7873315fd3a4ad41efe043e1c07c5",
"version" : "1.2024072200.0"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "61b85103a1aeed8218f17c794687781505fbbef5",
"version" : "11.2.0"
}
},
{
"identity" : "engine",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nathantannar4/Engine",
"state" : {
"revision" : "e9cf38a8a6e174f248b48a63b9b664315f67e347",
"version" : "1.9.5"
}
},
{
"identity" : "facebook-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/facebook/facebook-ios-sdk.git",
"state" : {
"revision" : "619d1772808425faa010d92293b26eeb9bc1d630",
"version" : "17.4.0"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "d1f7c7e8eaa74d7e44467184dc5f592268247d33",
"version" : "11.11.0"
}
},
{
"identity" : "generative-ai-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google-gemini/generative-ai-swift",
"state" : {
"revision" : "44b8ce120425f9cf53ca756f3434ca2c2696f8bd",
"version" : "0.5.6"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "dd89fc79a77183830742a16866d87e4e54785734",
"version" : "11.11.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "617af071af9aa1d6a091d59a202910ac482128f9",
"version" : "10.1.0"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "53156c7ec267db846e6b64c9f4c4e31ba4cf75eb",
"version" : "8.0.2"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "cc0001a0cf963aa40501d9c2b181e7fc9fd8ec71",
"version" : "1.69.0"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "a2ab612cb980066ee56d90d60d8462992c07f24b",
"version" : "3.5.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "040d087ac2267d2ddd4cca36c757d1c6a05fdbfe",
"version" : "101.0.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1",
"version" : "1.22.5"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1",
"version" : "2.30910.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac",
"version" : "2.4.0"
}
},
{
"identity" : "purchases-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/RevenueCat/purchases-ios.git",
"state" : {
"revision" : "c756269d79aa0f34e56d4a7f12f4dcc8c9381d47",
"version" : "5.20.3"
}
},
{
"identity" : "sdwebimage",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImage.git",
"state" : {
"revision" : "cac9a55a3ae92478a2c95042dcc8d9695d2129ca",
"version" : "5.21.0"
}
},
{
"identity" : "sdwebimageswiftui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImageSwiftUI",
"state" : {
"revision" : "451c6dfd5ecec2cf626d1d9ca81c2d4a60355172",
"version" : "3.1.3"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "d72aed98f8253ec1aa9ea1141e28150f408cf17f",
"version" : "1.29.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "swiftui-shimmer",
"kind" : "remoteSourceControl",
"location" : "https://github.com/markiv/SwiftUI-Shimmer",
"state" : {
"revision" : "0226e21f9bf355d40e07e5f5e1c33679d50e167f",
"version" : "1.5.1"
}
},
{
"identity" : "transmission",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nathantannar4/Transmission",
"state" : {
"revision" : "4c54a2880cbf5de8e826732ae04bbb89ff0e3bd4",
"version" : "1.7.2"
}
},
{
"identity" : "turbocharger",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nathantannar4/Turbocharger",
"state" : {
"revision" : "c504e85b01218f103936feddc0c60c61a1c20803",
"version" : "1.3.3"
}
}
],
"version" : 3
}
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock
snippet
Replace this line with the contents of your Podfile.lock!