C # mongodb model similar to Facebook

I am working on a project where the MongoDB model will be similar to Facebook. Therefore, we all know how FB works, a user "likes" a group / company page, and this user sees all the messages from this page.

Is the model below how should I design it? If the Page has a million votes, then each Post will have a million supporting documents. This does not seem right, there must be a better way that I do not think about.

Thanks.

public class Person { public ObjectId Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Page { public ObjectId Id { get; set; } public string Name { get; set; } public List<Like> PersonLikes { get; set; } } public class Like { public ObjectId Id { get; set; } public ObjectId UserId { get; set; } public DateTime DateLiked { get; set; } } public class Post { public ObjectId Id { get; set; } public ObjectId PageId { get; set; } public string Message { get; set; } public List<Like> PersonLikes { get; set; } } 
+6
source share
2 answers

My suggestion is that you only want to track what you like.

 public class Page { public ObjectId Id { get; set; } public DateTimeOffset Date { get; set; } public string Name { get; set; } public int NumberOfLikes { get; set; } } public class Post { public ObjectId Id { get; set; } public ObjectId PageId { get; set; } public DateTimeOffset Date { get; set; } public string Message { get; set; } public int NumberOfLikes { get; set; } } 

Then I would queue up the reaction (like or disliking) for insertion, "sentimental" information should not be stored in real time, right? This is not medicine, banking, etc.

 public class Like { public ObjectId Id { get; set; } public ObjectId ParentId { get; set;} public ObjectId UserId { get; set; } public DateTimeOffset Date { get; set; } } 

Where is the line? to the Likes collection. Why not become part of the page or post? Because if the message becomes viral (as you said, although most will not), you can get 1,000,000 people. Who will view this information other than analytical?

You must also ensure that the user can express his reaction only once per element.

+2
source

A message exists on only one page, so this is the page on which the message should be, and not on the page that owns the page.

 public class Person { public ObjectId Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Page { public ObjectId Id { get; set; } public string Name { get; set; } public List<Like> PersonLikes { get; set; } public List<Post> Posts { get; set; } } public class Post { public ObjectId Id { get; set; } public string Message { get; set; } public List<Like> Likes { get; set; } } public class Like { public ObjectId Id { get; set; } public ObjectId UserId { get; set; } public DateTime DateLiked { get; set; } } 
+1
source

All Articles