1

I am building a story site for pre school

The basic functions are students will be posting stories and others will be able to like/comment on that story

Below is the model of the DB

Stories
Story_Id
StoryTitle
StoryContent
StoryAuthor
StoryLikes {
LikerId,LikedTime
}
StoryComments{
AuthorId,AuthorComment
}

Is this model OK? How else can this be remodelled?

The problem I see here is, if I store it in this way, will be it faster when I query for all comments by a particular user and so on?

1
1

According to above mentioned description it seems that story comments is a separate collection which will encapsulate comments related to several stories along with story Id.But that approach will cause a performance overhead since it will require multiple queries for retrieval of information.As an alternate solution comments can be stored into stories collection as embedded documents which will consume less time duration of retrieval of comments Embedded documents are alternative to joins in MongoDB For more detailed description regarding embedded documents please refer the documentation as mentioned in following URL

https://docs.mongodb.org/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/

1
  • That's a horrible idea, because of the BSON size limit of 16MB. Furthermore, the performance issue depends on the point in time you need the information. E.g.: For a given story, what are the comments? So if a story "page" is selected, you'd have only two queries, which can be optimized to be rather fast and be scalable till the end of days. Nov 6 '15 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.