简体   繁体   中英

How to query the array from the firestore using javascript?

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

我想要的数组是突出显示的

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM