I am designing a schema of a forum website like StackOverflow in MongoDB. The questions collection will look something like this, the below is a question document,
{
id : 123,
questionTitle : "",
questionDesc : "",
questionAnswers : [
{id: "222",
answer : "",
answerBy : "",
answeredAt : ""
answerComment : [
{ id: "333",
commentBy : "", commentAt : "", comment :""
votes : [
{id : "444",
voteBy: "", voteAt : "", vote: "up/down"}
]
}]
},
{...}]
}
Now the problem is with updating comment of an answer or vote of an answer. I tried searching for ways to update nested array, but no luck. I referred this question, Updating nested arrays in mongodb but the answer suggested here is to redesign the schema.
Can somebody suggest, if there is way to update nested array, so that I can update a particular comment of an answer based on the id. Or can somebody suggest any other way to design this.
P.S: I was thinking of creating separate collection for answer and question, but don't think it is a good idea.
Hope I am clear with my question. Thanks in advance. :)