Struggling to find a solution for organizing Firebase data: Each user has posts with generated IDs, but how do I store these IDs in a user node efficiently?
Currently using string concatenation and treating them like a CSV file in my JS app, but that feels like a messy workaround.
What would be the best practice for handling this type of data structure?
Edit:
UserID:
- Username = "User Name"
- Posts = "id1, id2, id3, id4"
For adding a new post, I use a transaction to append the ID to the end of the string. When deleting an ID, I again utilize a transaction to remove it by running the following code:
removeElem(list, value) {
var separator = ",";
var values = list.split(separator);
for (var i = 0; i < values.length; i++) {
if (values[i] == value) {
values.splice(i, 1);
return values.join(separator);
}
}
return list;
},