I'm currently learning Firebase/NoSQL database modeling. I just ended watching the Firebase for SQL developers, but I still have few doubts.
Let's say I'm creating Instagram-styled app where users could share their photos and each user could like each photo.
So I would like to achieve two things: 1. Know which user has liked which photo. (So only one like per user for photo) 2. How many likes each photo has.
My current database looks like this:
{
"images": {
"100": {
"imageUrl": "../../image.png",
},
"101": {
"imageUrl": "../../image.png",
}
},
"users": {
"200": {
"name": "user1"
},
"201": {
"name": "user2"
}
},
"likes": {
"100": 1,
"101": 2
},
"likesPerUser": {
"200": {
"100": "true"
},
"201": {
"100": "true",
"101": "true"
}
}
"imagesPerUser": {
"200": {
"101": "true"
},
"201": {
"100": "true"
}
}
My question is related to the counter, that counts how many likes each photo has. Would the best practice be that I have them as their own "root"-object (current model) OR to create key-value pair for "likes" under the photo (and maybe do the same for authorID)?