Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

about user authentication and storing user data

I always had this doubt when I think about user data. If I created a site, for example a marketplace, when I’m going to store the data in the backend should I simply create a big array like this?

const user = [
  userName: "john",
  userWallet: 122,
  userProfilePic: "https://blbabablabl.com/ewxase"
  userCart: [
    {
      productName: "Air Jordan 1",
      price: 280,
      productImage: https://www.blablabla.com/image
    }
    
    {
      productName: "Louis Vuitton Bag",
      price: 900,
      productImage: https://www.blablabla.com/image
    }
    ...
  ]
]

and then for every user I create an array?
is this right?
what companies do in this situation?
where can I learn more about storing things in the backend?
I’m really lost when it comes to backend.

(I’m using firebase in my project cuz I don’t have the interest to study back-end. For now, I’m focusing more on the front-end)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The best way to do that would be to create separate sub-collection name carts under document of given user and store all necessary attributes for each cart item as document of that subcollection.

eg. You have user documents under users collection, then

cart document path would be as /users/3y1x1Dy6FYOGnSW0Sa4f1EUhiIo1/carts/WADVd2AZ91d7m9kSq3GP

See screenshots below:

enter image description here

enter image description here

Alternatively, you can create same level collection for carts and store userId field on cart’s document.

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading