Firestore:将一个文档与另一个列表文档合并 [英] Firestore: Join one document with another list document

查看:85
本文介绍了Firestore:将一个文档与另一个列表文档合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用firestore,正在尝试在两个文档之间进行查询,这是这种情况:

I've been working with firestore and I'm trying to make a query between two documents, this is the scenario:

  1. 我有一个名为user的文档,其中包含名称和费率属性例如:user = {name:'homer simpson',rate 4.5}
  2. 我有一个名为events的文档,它包含idUser,名称,日期(时间戳),状态例如:event = {name:'class one',date:'2020年9月25日,UTC-5,上午10:00:00',idUser:'1345648fdsfds',状态:'ACTIVE'}

一个用户可以有多个事件

我希望获得20个满足以下条件的用户:一个.他们应该在今天和接下来的两个星期之间进行活动b.它们应按费率排序

I'd like to get 20 user with these conditions: a. They should have events between today and next two weeks b. They should be ordered by rate

我一直在尝试对此进行查询,但实际上我无法做到这一点,也许有人可以告诉我我该怎么做或给出一些想法.

I've been trying to make a query for this but really I haven't been able to do it, maybe someone can tell me how can I do it or maybe give some ideas.

谢谢.

推荐答案

Firestore不提供任何类似SQL的联接.您一次只能查询一个集合.如果需要加入,则需要执行其他查询才能从另一个集合中获取匹配的文档.

Firestore does not offer any SQL-like joins. You can query only a single collection at a time. If you need to join, you will need to perform additional queries to get the matching documents from another collection.

因此,在NoSQL数据库中常见的是在集合之间复制数据以减少查询数量.缺点是,当数据更改时,您必须执行多个更新.您将必须决定要采用哪种方法.

For this reason, it's common in NoSQL databases to duplicate data between collections in order to reduce the number of queries. The downside is that you have to perform multiple updates when data changes. You will have to decide which approach you want to take.

这篇关于Firestore:将一个文档与另一个列表文档合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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