DEV Community

Niko Montana
Niko Montana

Posted on

Firestore Modelling Data

Hi,

I want to create an instagram clone with firebase and found some limitations while working on the datastructure.

As the documentation reccomends to keep the documents as small as possible and the collections big I have created this model.

+ Profile (collection)

  |--- uid (document)

      |--- userName (String)

      |--- firstName (String)

      |--- lastName (String)

      |--- profileImgUrl (String)

      |--- userName (String)

      |--- UserPosts (collection)

         |--- uid (document)

            |--- title (String)

            |--- createdAt (timeStamp)

            |--- description (String)

            |--- imgUrl (String)

I have decided to go with this model because by splitting Profile and Post into seperate root collections I am not able to query Posts by userName without a second query after I get the uid of the user.

My problem now is that I dont know how to write a query to get the posts of a user by userName

Top comments (1)

Collapse
 
razbakov profile image
Aleksey Razbakov

I would recommend to have 2 collections in root: Profiles and Posts. Each Post should have userId and userName (or any other field you want to be able to filter).