Firestore Group by field

Asked By: Anonymous

Below is my firestore collection structure

enter image description here

My vue method to get data

fetchResults(){
  db.collection('data').onSnapshot((querySnapShot)=>{
    let results = [];
    querySnapShot.forEach(doc=>{
      results.push(doc.data())
    })
    this.record=results;
  })
}

What I want is to query in the document like group by ID and order by sec_id desc.

How do I suppose to query like that?

So that I will get document grouped by ID field.


Solution

Answered By: Anonymous

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.)


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen Windows 10 Lisans Office 2019 Mac Satın Al follower kaufen instagram follower kaufen porno