Reputation: 3798
Let me show you the Firestore document structure.
How I can compare the stops
array values? because time 12:00 PM
will be different for each entry in the departure.
So actually I want to get the value of buss
where the my given value match to any value of the stops
array.
Upvotes: 0
Views: 240
Reputation: 139039
According to @Frank van Puffelen's answer, because Firestore does not support querying array members, you should consider change your database structure a little bit. So instead of using arrays you should use maps
. So inside each document you need to add a map
that will look like this:
Firestore-root
|
--- buses (collection)
|
--- busId (document)
|
--- buss: "/buss/OdGpiY..."
|
--- stops (map)
|
--- IQdng...526MpZ: true
|
--- pnwJ...4P3ef: true
As you can see, I have add a new map named stops
inside the bus document that contains as key, the name of the station and as a value the boolean true
. Using this database structure you can query your database based on elements that exist inside the map like this:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference busesRef = rootRef.collection("buses");
Query query = busesRef.whereEqualTo("stops.IQdng...526MpZ", true);
Upvotes: 1
Reputation: 600006
From the Firestore documentation on arrays:
Although Cloud Firestore can store arrays, it does not support querying array members or updating single array elements.
To allow querying for routes that contain a certain stop, you should store an additional field in the document that contains the stops as a set:
stops
IQdng...526MpZ: true
Now you can query for routes with that stop by doing:
routesRef.whereEqualTo("stops.IQdng...526MpZ", true)
You'll still need your original structure for the stops too, since that's the only way to know the order of the stops and the time of each stop.
Upvotes: 0