views:

34

answers:

1

I am building a library using mvc, mongodb and asp.net membership.

When a user browses the site logged in (logged out is auto set to preview) I need to check if they have purchased the current movie and if they have they can see the full set of features otherwise they have to purchase the video or watch the preview.

I have a Movie model below:

public Guid Id { get; set; }
public string Slug { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public double Price { get; set; }
public string PreviewUrl { get; set; }
public string MovieUrl { get; set; }
public DateTime CreatedOn { get; set; }
public string CreatedBy { get; set; }
public DateTime ModifiedOn { get; set; }

public IEnumerable<User> Users;

public Movie() {
    Id = Guid.NewGuid();
    CreatedOn = DateTime.Now;
    ModifiedOn = DateTime.Now;
}

Maybe there is a better method to approach this. Maybe an order or something?

A: 

I'm going to suggest a very basic solution. Assuming that you keep track of purchases somewhere in the DB (be it MongoDB or not) you could write a routine that queries the purchases by the id of the user and the id of the movie. So essentially you always keep track of who has purchased what thus giving yourself the ability to know if a person has purchased a movie using on simple query like I've illustrated bellow:

Purchases table:

RecordID  UserID  MovieID
1         10      233
2         89      720

Query

db.purchases.find({'UserId': 10}, {'MovieID' : 233})

Should return

RecordID  UserID  MovieID
1         10      233    
Am
Wouldn't this defeat the purpose of mongodb though and represent a RDBMS?
Daniel Draper
@Daniel Draper, IMO MongoDB is not just about denormalizing your data. It's really there to allow storing large amounts of data quickly and easily without a predefined definition by sacrificing the ACID properties of RDBMS systems. However its true that he could simply keep the UserIds against the Movie records to be less RDBMS like.
Am