(MongoDB) database structure for Q&Answer website
I'm trying to make a website similar to Yahoo & Answer or StackOverflow
(different category, no competition), and I'm stuck at this point, I'll
really appreciate any guidance from you guys as I'm very new to MongoDB.
I'm using Express framework on Node.js and MongoDB by the way.
The problem is to find the most efficient way to structure the database
for users and questions/answers data.
Currently, there is a Questions model, inside there's a document for each
category. Each document contains the question itself, the answers, and
other info as described below:
math{
OpenQuestions{
'x+2=5, whats x?' : {
asker: 'jack',
likes: 12,
answers: {
'x is 3' : {
answerer: 'nicolas',
likes: 25
},
'x is 2' : {
answerer: 'MATHSUX',
likes: 0
}
}
}
}
ClosedQuestions{
//same as openquestions
}
}
In this way it's very easy to display the questions as we can easily
retrieve questions based on the object's creation time and fetch them
accordingly on the main question page.
However, if an user wants to see the questions he has asked, the only way
I can think of is going through each
subject.OpenQuestions.QuestionItSelf.asker, and check if it's the user
himself, then fetch all the object matches for this username, it would be
an immense calculation. I'm sure there exists a much better way, what do
you all think?
No comments:
Post a Comment