0

So, I have this firestore that looks like the picture below. How can I query the arrays that I highlighted only to javascript format?

The array that I want is the highlighted one

How the Getting started with firestore does is by using [array-contains](https://firebase.google.com/docs/firestore/query-data/queries#:~:text=const%20q%20%3D%20query(citiesRef%2C%20where(%22regions,array_contains_filter.js) which looks like this as their example:

const q = query(citiesRef, where("regions", "array-contains", "west_coast"));

but what I see is that it only displays the word 'west_coast', what I want is that it will display any information in the field called 'amount' and 'title' as the picture above

  • The data that is shown depends on the data which you are printing after getting the data from Firestore. Can you share the full code where you are querying and printing the data? It seems you are doing something wrong after getting the data. – Prabir Dec 10 '21 at 13:50
  • Take a look at the answers of this question https://stackoverflow.com/questions/54600915/firestore-how-to-query-data-from-a-map-of-an-array – Khalid Dec 10 '21 at 15:40

1 Answers1

0

I'm afraid you can't. You need to retrieve the whole products array and filter locally.

Which leads to how your data is structured in Firestore. If that's the query you need, your data must have probably been structured differently.

For example:

  • products could be a subcollection of ordered
  • or, ordered documents may store the data you need to query in a separate, simplified array (like titles: [...], amounts: [...], but that won't help for sorting or ranges in numbers anyway).

Take a look at: https://firebase.google.com/docs/firestore/manage-data/structure-data for examples and use cases like this.

maganap
  • 2,414
  • 21
  • 24