MongoDB Schema Design - Voting on Posts

后端 未结 2 1541
灰色年华
灰色年华 2021-02-04 16:00

Consider I have a website where I\'ve got a bunch of articles and people can vote on the articles they like.

I want to be able to query to get the articles with the most

2条回答
  •  悲哀的现实
    2021-02-04 16:31

    The schema you choose depends largely on your use-case..If you are expecting a lot of votes/comments and want to process them independently of the post they belong to, you might keep them in a separate collection with postID as the 'foriegn key'..However, if you want to load all the votes when you load a particular post and the votes in themselves don't have any meaning without the post that houses them, then go for the embedding (in your case, the first) approach.

提交回复
热议问题