0

i want to create a query in Flutter firebase for search in array, this is my firebase db enter image description here

I want get all users where level array contain elementari. I've try this but not working.

_firestore
        .collection('users')
        .where('level', arrayContains: {"name": "elementari"})
        .snapshots()
        .listen((data) => data.documents.forEach((doc) => print(doc["name"])));

PS: I've already index the database. thanks!!

Stefano Toppi
  • 626
  • 10
  • 28
  • 1
    Does this answer your question? [How to query documents containing array of objects in Firestore collection using whereArrayContains() filter on Android?](https://stackoverflow.com/questions/52351321/how-to-query-documents-containing-array-of-objects-in-firestore-collection-using) – radulle Jan 13 '20 at 13:07
  • 1
    The `arrayContains` operator checks if the exact item you pass exists in the array field. So you must pass the entire item, not just an individual property. If you want to be able to search on just the names, consider adding an additional field to the document with just the names and then query on that. So something like `.where('levelNames', arrayContains: "elementari")`. – Frank van Puffelen Jan 13 '20 at 15:55

0 Answers0