Model and Query data in Firestore to get items in directories

蹲街弑〆低调 提交于 2020-03-05 05:04:04

问题


I want to model data in firestore to get items in directories shared by several users (folders are secured with security rules).

My current model is as follows:

  • /folders/{folder}/folders/{subfolder}
  • /folders/{folder}/items/{item}
  • /folders/{folder}/folders/{subfolder}/items/{item}

A user can access several folders and if he accesses the root folder he can also access the subfolders. He can also access subfolders (if he has permission) and his access to the root folder is restricted.

The idea is that the system can list all the items that the user can access.

Is there a way without having to make a query for each folder?


If I make a query for each folder I would have a query for each root and for each subfolder. It would be many queries

Duplicating the access roles of the folders in the items could be an option but with a big problem when the permissions are modified

The directory can only have up to two depth levels (root and subfolders).


回答1:


You could have a document per user where you can write every folder id the user can access. Then you could query only these folders.

And if you have a lot of events the users can access i would recommend to show a folder structure to the user like in a file system. So you could save a lot of unnecessary reads for documents the user does not need.



来源:https://stackoverflow.com/questions/56799381/model-and-query-data-in-firestore-to-get-items-in-directories

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