Can i search a Firestore DocumentID with a List<String>
?
I am trying to search through my collection with some selection of documentID in a List. The List will consist of few String. Can I search through the Firestore collection using this?
This is the List:
List<String> _selectedBusStop = List<String>();
This is the code I used in finding the DocumentID based on the list that is in here.
Future <void> saveRoute(_selectedBusStop) async{
Firestore.instance.collection('markers').where('BusstopName', isEqualTo: _selectedBusStop)
.snapshots().listen((location) {
if(location.documents.isNotEmpty){
for (int i = 0; i < location.documents.length; i++){
initRoute(location.documents[i].data, location.documents[i]);
}
}
});
setState(() {
});
}
I am using where
and isEqualTo
or is this approach wrong? Any idea how to make it work for this part? Thank you in advance for your help.
Update:
This is how my Firestore looks like:
The List
have some of the BusstopName
but not all of it. I do not want to retrieve all the data from the Firestore just the one that is in the List
. Sorry for causing so many misunderstanding.
_selectedBusStop
a documentId or the content of the fieldBusstopName
in the document? – thomasBusstopName
(array field) is exactly equal to_selectedBusStop
List or that array contains any value from_selectedBusStop
? – Dharmarajcollection("markers").doc("yourDocumentId")
and then filter out only the documentSnacpshots that actually exist. (you can call DocumentSnapshot.exists). You would need to check the flutter firestore sdk documentation to get the correct syntax. – thomas_selectedBusStop
is the DocumentID and as well as one of the Data inside the document. Sorry for not making it clear. @thomas – randomstudentBusstopName
is not an array field it is only aString
. The name of the DocumentID is actually the same as theBusstopName
in the document. I will update my question. Sorry for causing so many misunderstanding. – randomstudent