Firestore按领域分组 [英] Firestore Group by field

查看:59
本文介绍了Firestore按领域分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的Firestore集合结构

Below is my firestore collection structure

我的vue获取数据的方法

My vue method to get data

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

我想要的是像group by ID and order by sec_id desc这样的文档进行查询.

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

我该如何查询?

这样我就可以按ID字段对文档进行分组.

So that I will get document grouped by ID field.

推荐答案

作为NoSQL类型数据库,Cloud Firestore不提供任何聚合查询,例如分组,求和,最大值等.您必须在自己的数据库中执行这些操作.客户代码.对于您的情况,这意味着您将必须查询集合中的所有文档,然后按所需的字段对它们进行分组.另外,您可以维护一个单独的预分组文档集合来满足您的查询. (在NoSQL类型的数据库中,这样的数据复制很常见.)

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

这篇关于Firestore按领域分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆