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)
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:
Alternatively, you can create same level collection for carts and store userId field on cart's document.