loading...

Firestore Modelling Data

nikomontana profile image Niko Montana ・1 min read

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

Posted on by:

Discussion

pic
Editor guide
 

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).