Home > Software engineering >  Firebase Firestore Mulitple Condition Clauses or Cloud Functions, with Flutter
Firebase Firestore Mulitple Condition Clauses or Cloud Functions, with Flutter

Time:10-08

I'm currently using Flutter to develop, and I have an issue I understand that according to the Firebase Documentation: you can only perform a search using just one Array Contains clause.

In my Firestore, I have a Collection which in its documents, it has the field State, City, and Zone, which should all be queried with array contains.

I would let it go, but another programmer mentioned that through CloudFunctions, there is a way to get the Mulitple Array Queries only that it will be slower.

So in a perfect world, I should be able to query with an Array of Zones [Zone1, Zone2, Zone3], with and array of Cities [San Diego, Los Angeles, Washington] and an Array of States [CA, WA, NY] and show results for those.

Any Ideas?

CodePudding user response:

through CloudFunctions, there is a way to get the Mulitple Array Queries only that it will be slower.

Cloud Functions accesses Firestore through the Admin SDK. While it is a separate SDK, most limitations come from the Firestore backend and not its SDK. In this case the Admin SDK too can only have a single array-contains clause per query.

You might want to go back to that customer and ask if they can clarify how they think Cloud Functions could be used here. They probably have something else in mind than this feature suddenly existing there.,

CodePudding user response:

filter only by "zones" that will make the results you are looking for. I'm guessing here that you want to filter with AND. If so, in you case

Zones [Zone1, Zone2, Zone3] AND Cities [San Diego, Los Angeles, Washington] AND States [CA, WA, NY]

is equal to Zones [Zone1, Zone2, Zone3] since a every document should be like

{ state: 'CA', city: 'San Francisco', zone: 'soma' }

for the case that you only have state and cities in the filter then filter for city, same when only you have states

  • Related