Firestore Group by field

前端 未结 3 1491
甜味超标
甜味超标 2021-01-25 23:19

Below is my firestore collection structure

My vue method to get data

fetchResults(){
  db.collection(\'data\').onSnapshot((querySnapShot)=>{
         


        
相关标签:
3条回答
  • 2021-01-26 00:00

    Instead of calculating the data with an aggregate query, the data should be saved in the document itself using client side logic to update the aggregate data each time the document is changed or use cloud functions.

    See this post from Google blog.

    https://firebase.google.com/docs/firestore/solutions/aggregation

    0 讨论(0)
  • 2021-01-26 00:10

    You can do using

    fetchResults(){
      db.collection('data')
     .orderBy("id", "asc")
     .onSnapshot((querySnapShot)=>{
         // Do something
      })
    }
    

    More information visit https://firebase.google.com/docs/firestore/query-data/order-limit-data and you can also apply filter using click on click on filter icon

    0 讨论(0)
  • 2021-01-26 00:13

    As a NoSQL type database, Cloud Firestore doesn't offer any aggregation queries such as grouping, sum, max, etc. You have to perform these operations in your client code. For your case, this means you will have to query for all the documents in the collection, then group them by whatever fields you want. Alternatively, you can maintain a separate collection of pre-grouped documents to satisfy your query. (Duplicating data like this is common in NoSQL type databases.)

    0 讨论(0)
提交回复
热议问题