A Quick Guide to Data Models in Firestore

  • Slides: 6
Download presentation
A Quick Guide to Data Models in Firestore By: Dr. Taha Havakhor Assistant Professor

A Quick Guide to Data Models in Firestore By: Dr. Taha Havakhor Assistant Professor of MIS

Principles of Data Modeling • Keep in mind that Firestore is often subscribed to

Principles of Data Modeling • Keep in mind that Firestore is often subscribed to rather than just a one time query/response (the realtime nature of the system). • Always consider How will I query this data store? • Use subcollections, arrays, and maps (associative arrays) sparingly (rarely) • Use auto-id's vs human readable id's, e. g. use 000 kzt. LDGaf. F 4 u. Kb 8 Cal rather than banana for document ID’s to the extent possible

Deep Data Issue { "users": { "user_id_1": { "username": "user one", "profile_pic": "some_url", "articles":

Deep Data Issue { "users": { "user_id_1": { "username": "user one", "profile_pic": "some_url", "articles": { "article_id_1": { "title": "Firebase is so cool", "comments": { "comment_id_1": "First comment", "comment_id_2": "I like trains" } }, "article_id_2": { "title": "Firestore rocks!", "comments": { "comment_id_1": "SQL it's better", "comment_id_2": "Do you know the wae? " } } }

Deep Data Issue – separate as much as possible { "users": { "user_id_1": {

Deep Data Issue – separate as much as possible { "users": { "user_id_1": { "username": "user one", "profile_pic": "some_url" } }, "articles": { "article_id_1": { "author": "user_id_1", "title": "Firebase is so cool", "comments": { "comment_id_1": "First comment", "comment_id_2": "I like trains" } }

Don’t forget about redundancy { "users": { "user_id_1": { "username": "user one", "profile_pic": "some_url"

Don’t forget about redundancy { "users": { "user_id_1": { "username": "user one", "profile_pic": "some_url" } }, "articles": { "article_id_1": { "author": { "id": "user_id_1", "username": "user one", "profile_pic": "some_url" }, "title": "Firebase is so cool", "comments": { "comment_id_1": "First comment", "comment_id_2": "I like trains" } }

"articles": { { "article_id_1": { "users": { "author": { "user_id_1": { "id": "user_id_1", "username":

"articles": { { "article_id_1": { "users": { "author": { "user_id_1": { "id": "user_id_1", "username": "user one", "profile_pic": "some_url" "article_counter" : 2, }, "author_of_articules": [ "title": "Firebase is so cool", "article_id_1", "comments": { "article_id_2" "comment_id_1": { ], "comment": "First comment", "author_of_comments": [ "author": { "comment_id_1" "id": "user_id_1", ] "username": "user one", }, "profile_pic": "some_url" "user_id_2": { } "username": "user two", }, "profile_pic": "some_url_2", "comment_id_2": "I like trains", "author_of_comments": [ "author": { "comment_id_2" "id": "user_id_2", ] "username": "two", } "profile_pic": "some_url_2" }, } } }