I am working on a database feature that allows users to 'like' comments on posts.
Is there a way for me to sort the comments based on the number of likes they have?
Although I am aware of using .orderByChild()
, my issue lies in not having a separate child for the 'like' count.
Currently, I store user UIDs and timestamps within the original commentID child to handle likes.
Would it be feasible to retrieve comments based on the child with the highest number of sub-children?
The structure of my database is as follows:
{
"users" : {
"$uid" : {
"posts" : {
"$postID" : {
"postText" : "blah blah blah",
"comments" : {
"$commentID" : {
"commentText" : "blah blah blah",
"likes" : {
"UID01" : "1622035190516",
"UID02" : "1622036141955",
"UID03" : "1622036145134",
}
},
"$commentID" : {
"commentText" : "blah 2 blah 2 blah 2",
"likes" : {
"UID01" : "1622036141955",
"UID02" : "1622036145134",
}
}
}
}
}
}
}
}