Apply join like SQL to get data from multiple collections - Firestore

给你一囗甜甜゛ 提交于 2021-02-08 11:30:24

问题


I have a project database setup on Firestore. For some case I just want to pull out data from multiple collections and combine them like SQL. Also we have provision of pagination with filters applied on data. So its like applying where condition and joining multiple collections to get relevant data. Can anybody help me to get this result?


回答1:


Firestore read operations get documents from a single collection, or a group of collections of the same name. It has no support for server-side join operations.

The two common workaround for this are:

  1. Load the additional data from your application code, also referred to as a client-side join. This affect performance a bit, but not nearly as much as you may expect - so definitely try and measure performance before ruling it out.
  2. Duplicate the data that you need from the secondary collection. This way you store more data, and your write operations become more complex, but reading the data is fast and simple.

The second solution is also the only way to have conditions on the data from both collections, as there's also no way to query across collections.

While this may all be very unexpected if you come from a background in relational databases, it is actually very common amongst NoSQL solutions and is one of the reasons they can scale so well to massive data sizes.

To learn more, I highly recommend reading NoSQL data modeling and watching Getting to know Cloud Firestore.



来源:https://stackoverflow.com/questions/65663943/apply-join-like-sql-to-get-data-from-multiple-collections-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!