How to use arrayContains with list in FlutterFire that returns documents with ONLY the values in the given list

Viewed 17

Example:

List<String> vehicleList = ['bus', 'plane']
var tarifRef = _firestore
        .collection("vehicles")
        .where("models", arrayContains: vehicleList );

Is there a way I can return documents that contain only the items in the vehicleList ?

1 Answers

What you're trying to do can only work with Firestore if the items in the list always have a predictable order. Typically you do this by making sure they are sorted by their natural sort order before you write the document, and in the list that you pass to the query. If the lists are identical, you can simply use a normal equality filter to compare them. If the lists contain the same strings, but they are not in the same order, then the equality check won't match them.

See also:

Related