Firestore-如何对2个集合进行建模和查询关系-IOT用例-v2 [英] Firestore - How to model and query relation of 2 collections - IOT use case - v2

查看:59
本文介绍了Firestore-如何对2个集合进行建模和查询关系-IOT用例-v2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

延伸到我的问题 Firestore-如何建模和2个集合的查询关系-IOT用例

我现在看了有关此视频,并建议使用文档ID建立关系模型. https://www.youtube.com/watch?v=jm66TSlVtcc 跳至6 :07

I'ved now seen a video on this, and this recommends modelling relations using document ID. https://www.youtube.com/watch?v=jm66TSlVtcc skip to 6:07

我想知道在这种情况下是否可以解决(将我原来的问题中的示例修改为适合YouTube关于Firestore关系的建议:

I want to know if it would work in this case (modifying the example from my original question to fit to this youtube recommendation of firestore relation:

例如:我有2个不同的收藏集-跟踪和地点

Eg: I have 2 different collection - tracking and venue

跟踪<-集合

1. document(xyz123)
venueId = "abcd1234"
timestamp = 10/09/2019 10:00

2. document(xyz567)
venueId = "efgh3456"
timestamp = 10/09/2019 11:00

场地<-收藏

1. document(abcd1234) <-- notice i shift the device_unique_identifier here instead
name = "room A"
// device_unique_identifier = "abcd1234" <-- this is unique name

2. document(efgh3456) <-- notice i shift the device_unique_identifier here instead
name = "room B"
// device_unique_identifier = "efgh3456" <-- this is unique name

主要问题: 我想查询文档xyz123并获取行中场地的名称.因此输出为:

Main question: I would like to query document xyz123 and get the name of the venue in the row. So the output would be:

document(xyz123)
device_unique_identifier = "abcd1234"
timestamp = 10/09/2019 10:00
venue.name = "room A"

关于另一个可能的附加问题,当插入跟踪数据时,是否可以将场所数据作为对象自动插入到Firestore后端中而无需查询场所数据?

On another possible extra question, when inserting the tracking data, would it be possible to auto insert the venue data as an object in firestore backend without the need to query venue the data ?

推荐答案

Firebase无法做到这一点. Firebase中没有JOIN的概念.如果数据位于两个单独的文档中,则需要重新考虑如何存储数据(以便可以一次调用所有数据,等等),或进行实现最终所需输出所需的所有调用.

This is not possible with Firebase. There's no concept of JOIN in Firebase. If the data lives in two separate documents you'll need to either reconsider how you're storing the data (so that the data can be called all at once, etc.) or make all the calls needed to achieve the end desired output.

您绝对可以像执行操作一样存储数据,但是您无法查询一个文档以获取具有当前结构的输出.

You can definitely store the data like you're doing, but you can't query one document to get the output with the current structure.

这篇关于Firestore-如何对2个集合进行建模和查询关系-IOT用例-v2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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