How best to structure nested data in firebase -
say have folders, documents, , comments. understanding we don't want nested data, there seem few choices on how store hierarchical data:
a. encoding last 2 steps of logical path in ref:
/users/$user_key /folders/$folder_key /folder_documents/$folder_key/$document_key /document_comments/$document_key/$comment_key /comment_likes/$comment_key/$user_key b. encoding full logical path in ref, adding path components client can efficiently fetch needs:
/users/$user_key /folders/info/$folder_key /folders/documents/$folder_key/info/$document_key /folders/documents/$folder_key/comments/$document_key/info/$comment_key /folders/documents/$folder_key/comments/$document_key/likes/$comment_key/info/$user_key c. encoding no path information in ref, , adding indices fetch subsets of data such comments document.
/users/$user_key /folders/$folder_key /documents/$document_key /comments/$comment_key /likes/$comment_key/$user_key (still want 2 levels here, probably) are there others haven’t considered?
i doing because that's what's suggested in link above… don’t because requires knowing parent key in order fetch object. on client know anyway, things messier when adding server component handle side-effects notifications. example, if likes comment , want send notification, server needs know document key fetch comment text liked. work-arounds seem replicating data or passing parent keys around.
i think b might work pretty well, feels little baroque.
i thought of c, , wonder performance implications are.
Comments
Post a Comment