Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have the following classes that I want to store.

public class StorableObject
{
    public string Id { get; set; }
}

public class User : StorableObject
{
    public string Name { get; set; }
}

public class Project : StorableObject
{
    public string Name { get; set; }
    public User Owner { get; set; }
    public ICollection<Task> Tasks { get; set; }
}

public class Task : StorableObject
{
    public string Name { get; set; }
    public User Owner { get; set; }
    public ICollection<Timesheet> TimeSheets { get; set; }
}

public class Timesheet : StorableObject
{
    public User Owner { get; set; }
    public DateTime Timestamp { get; set; }
    public TimeSpan Duration { get; set; }
}

Schema design has a lot to do with which queries you'll be needing, so let me try to explain a bit. I'll need to do fast queries to extract:

  • all Tasks on a Project
  • all Timesheets on a Task
  • all Projects a user owns
  • all Tasks a user owns
  • all Timesheets a user owns.

I also need some summations like get total time spent on a Project or Task in a given time period and total time spend per user in a given period. (MapReduse I suppose)

I started out (after reading this blog) with 4 collections (Users, Projects, Tasks, Timesheets), each child would have a parent reference so I could construct my domain model in my business logic.

However after watching this I've changed my mind and now going for a more embedded approach.

{
   _id: 123456789,
   owner_id: 123,
   name: "My Project",
   tasks: [
            {
               owner_id: 123,
               name: "My Task",
               timesheets: [
                             {
                                owner_id: 123,
                                ...
                             }
                           ]
            }
          ]
}

What's your take? Is that a fast schema design?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.