I am working on a angular project with firestore as database.In database i stored a document with name uid which is an array of uids.How do I query on them.I searched a lot but all the suggestions are with firebase and not with firestore.
1 Answer
Update 29. May 2019
You can now do this. There is an array_contains query: https://firebase.google.com/docs/firestore/query-data/queries#array-contains You can use the array_contains operator to filter based on array values. For example:
citiesRef.where("regions", "array-contains", "west_coast")
regions is an array of strings and the above query will return only the documents that have "west_cost" in the array.
====================
Old answer:
Unfortunately you can't. from the docs: https://firebase.google.com/docs/firestore/solutions/arrays
Although Cloud Firestore can store arrays, it does not support querying array members or updating single array elements. However, you can still model this kind of data by leveraging the other capabilities of Cloud Firestore.
You can try making a map of values as suggested in the docs. This works in most cases unless you store more than 10k user uids on a single document, than you would run in some of the limitation of firestore.
https://firebase.google.com/docs/firestore/quotas
Maximum number of index entries for each document
20,000
The number of index entries is the sum of the following for a document:
The number of single-field index entries The number of composite index entriesCloud Firestore automatically creates two single-field index entries for each field, one in the ascending index and one in the descending index.
Considering the limit of 20,000, each document can index a maximum of 10,000 fields minus the document's number of composite index entries.