Reputation: 3079
I'm not proficient in MongoDB and I have short question. What is the best structure for Questions - Answers Collections. Should I separate them to different collections or keep Answers as a property of Question? To give you more details:
userId
, votes
and of course answer
propertiesIt will be something like stackoverflow but much simpler. Thanks in advance.
Upvotes: 1
Views: 188
Reputation: 3150
I would keep them in two separated collections. As you said you have to be able to query in the questions collection so make a questions collection, you only have to show up answers realted for a specific selected question but will have some specific fields as you mentioned like votes. If we think about stackoverflow for example, you see the questions : click on the question --> then you can query an answers collection for the answer related to that question, also for answers you can have comments which if you not expect insane much of them can kept in a list along with the answer.You can keep the answers of the questions in a collection with a reference and an index on the question id.
Something like his one:
questions:
{
"_id" : ObjectId("52205df3d6c893638bc2aa14"),
"q" : "What is hip?",
"v" : 1000
}
answers :
{
"_id" : ObjectId("52205e72d6c893638bc2aa15"),
"q_id" : ObjectId("52205df3d6c893638bc2aa14"),
"a" : "Tell me, tell me!",
"u" : "uid",
"v" : 153,
"c" : [
{
"c" : "Cool",
"u" : "uid",
"v" : 100
}
]
}
Upvotes: 1