Firebase Cloud Firestore database structure

Mahi!
feedflood
Published in
2 min readSep 1, 2019

It’s not been a long time with firebase but one important thing learning firebase is how it structures the data. Cloud Firestore stores data in the form of JSON object but before even that, there are collections and documents and bla bla….

So naturally, for someone coming from SQL background, it takes time to understand how it all sums up together. So here is my general overview as to how to visualize the data to store it inside cloud Firestore.

First, let’s take a simple example to work with. Suppose you want to maintain a movies list so, for example, your list is like the following:

movies{Avatar:{
Director:James Cameroon,
Year:2009,
cast:{
actor1:Zoe Saldana
actor2:Sam W.
}
},
Titanic:{
Director:James Cameroon,
Year:1997,
cast:{
actor1:Kate Winslet,
actor2:Leo
}
},
FightClub:{
Director:David Fincher,
Year:1999,
cast:{
actor1:Brad Pitt,
actor2:Ed Norton
}
}}

This is a simplified structure now how do we store it in cloud Firestore?

The structure of cloud Firestore is like this:

Collections{  Documents:{
Documents:{...},
key:value
}
}

So your main list name is the collection (movies)

inside the collection(movies), each record has its own document (movie-name)

and a document contains key-value(director: James Cameroon) pair for further details about it or it can contain another sub-document( cast:{
actor1: Brad Pitt
actor2: Ed Norton
}
)

This way you can imagine the collection to be your Table, Document to be your row and each key-value pair a cell of the row. we create another table in SQL for this thing.

--

--