0

If MySQL table is like:

table name: members

mem_name      dep_date      dep_cash
NEBU          01/01/2019    500
ASHISH        01/01/2019    700
YOGESH        01/01/2019    600
NEBU          01/02/2019    500
ASHISH        01/02/2019    1000
NEBU          01/03/2019    1200

How above table will be created in Firestore? What would be in "collection" part what would be in "documents" part and where all record to be kept in Firestore?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • You can also check **[this](https://stackoverflow.com/questions/53053768/what-is-the-correct-way-to-structure-this-kind-of-data-in-firestore/53057707)** out. – Alex Mamo Nov 01 '19 at 13:15

2 Answers2

3

There's no singular correct translation of a relational database model to a Firestore database model. In NoSQL databases, your data model often depends on the use-cases of your app.

The most direct translation would be to have a collection of users, with each document in that collection representing a single user from your table. And while that might be a great data model for one app, it could be a really bad data model for another app.

To learn how to think about NoSQL data modeling in general, I recommend reading NoSQL data modeling, and for Firestore specifically you should watch the Getting to know Cloud Firestore series.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

As a follow up answer, you will often structure your Firebase depending on what kind of queries you will be running - and denormalizing and duplicate data is common.

Sometimes a visual can help understand Firebase so in this case, one such structure could be:

members //a collection
   member_id_0 //a document
      mem_name: "NEBU" // fields within the document
      dep_date: "01/01/2019"
      dep_cash: "500"
   member_id_1
      mem_name: "ASHISH"
      dep_date: "01/01/2019"
      dep_cash: "700"

where the member id's are created with .addDocument which automatically creates a unique documentId

Also, dates are a bit tricky so storing them like this may be a better option

  dep_date: "20190101"

or even storing it as a Date object.

Jay
  • 34,438
  • 18
  • 52
  • 81
  • Thanks Jay.... I am new to Firestore... its a little time taking subject.... I will go more through examples... – Nebu Mathew Nov 02 '19 at 07:27