Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# mongodb model like Facebook

I'm working on a project where the MongoDB model will be similar to Facebook. So we all know how FB works, a user "likes" a band/company page, and that user will see all the posts from that page.

Is the below model how I should design this? If a Page has million likes, then each Post will have a million sub documents of Like. That does not seem right, there must be a better way that I cant think of.

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; }
}
like image 700
Curtis Avatar asked Oct 03 '15 20:10

Curtis


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

My take assuming you only want to track likes

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; }
}

I would then queue the Reaction (Like or Dislike) for insertion, "sentiment" information doesn't have to be stored in real time, does it? These are not medications, bank transactions, etc.

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

Queue where? to a collection of Likes. Why not part of the page or post? Because if a post goes viral (as you said even though the majority won't), you may end up with a 1,000,000 likes. Who is going to browse this information other than an analytic engine?

You also have to ensure a user can only express their reaction only once per item.

like image 90
Alex Nolasco Avatar answered Oct 05 '22 23:10

Alex Nolasco


The post only exists on one page so it´s the page that should own the post, not the post owning 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; }
}
like image 22
jrb Avatar answered Oct 06 '22 01:10

jrb