I have a social media site where there are posts and there are comments and people can upvote or downvote posts and comments. Here is how a post looks like in form of an object on my firebase firestore database-
{
author: 'Pranav',
heading: 'randomHeading',
content: 'randomContent',
votes: 3,
comments: [
{
id: 123,
author: 'Pranav'
content: 'commentContent',
heading: 'commentHeading',
votes: 2,
},
{
id: 124,
author: 'Pranav2'
content: 'commentContent2',
heading: 'commentHeading2',
votes: 3,
},
{
id: 125,
author: 'Pranav3'
content: 'commentContent3',
heading: 'commentHeading3',
votes: 4,
}
]
}
Now I want to add functionality to update the votes of a particular comment but don't know how to access the comment with its ID, using the firebase firestore functions.
This is how I am getting the post doc in my code, just for reference if you can answer with the exact code for the query.
function voteComment(postId, vote){
const docRef = doc(db, 'posts', postId);
updateDoc(docRef, {<update-goes-here>})
}