Firestore: How to query data from a map of an array
As Doug said, you can't query it, but, if you could structure your data to something that looks like this
- Store your data as a map
- Use
id
as key andname
as value - Now you can write a query that can get all the documents where contacts have
id=1
db.collection("test").where("contacts.1", ">=", "").get()
You currently can't build a query that looks for an object field within an array. The only things you can find in an array are the entire contents of an array element, not a part of an element.
With NoSQL type databases, the usual practice is to structure you data in a way that suits your queries. So, in your case, you're going to have to structure you data to let you find documents where an array item contains a certain string. So, you could create another array that contains just the strings you want to query for. You will have make sure to keep these arrays up to date.
You could also reconsider the use of an array here. Arrays are good for positional data, but unless these contacts need to be stored in a certain order, you might want to instead store an object whose keys are the id, and whose field data also contains the id and name.