Question

I've recently started to look at RavenDB, and I've tried to see if it is a fit for some of our projects. However I have run into some questions regarding the "right" way to model a simple data structure. I'll try to describe it:

  • There are 3 types of objects: Guides, Categories and Links
  • A "root" Guide can contain 0 or more sub-Guides
  • A Guide can contain 0 or more Categories
  • A Category can contain 0 or more Links

Visually the structure would be:

  • root-Guides (0 or more)
    • Sub-Guides (0 or more)
      • Categories (0 or more)
        • Links (0 or more)
    • Categories (0 or more)
      • Links (0 or more)

In the actual data there is about 20 root Guides and about 3-5 sub-Guides under each root Guide. Under each Guide (both root- and sub-Guides) there are 15-25 Categories. And under each category there are between 5 to 20 Links.

My initial thought were to model it like this (simplified model):

Guide
---------------
Id
ParentGuideId
Title

Category
---------------
Id
GuideId
Title

Link
---------------
Id
CategoryId
Title

This is pretty much the relational model and I realize this might not be the correct way to model data in RavenDB. So what is the alternative? The problem, I guess, is that I don't want to store the Hierarchy like this:

Guide
---------------
Id
Title
SubGuides
Categories

SubGuide
---------------
Title
Categories

Category
---------------
Title
Links

Link
---------------
Title

Because it would results in documents with potentially thousands of sub-objects. Please keep in mind that the model above is simplified. In reality there are much more data on each type so the 20 root-Guide documents in RavenDB would be huge if we went with this model.

Are there any alternatives? Maybe it's my years of bad relational-db upbringing talking, but maybe this scenario simply doesn't fit RavenDB as well as it fits SQL?

EDIT (added basic queries)

Access to the data is fairly simple. I have the following requirements:

  1. Select a list of root-guides with all sub-guides.
  2. For a specific guide (root or sub) get all sub-guides (if root), categories and links.

That's essentially all I need. However, one of the reasons to evaluate RavenDB or similar, was to add some search capabilities. As I've already mentioned there are some more info on links, categories and guides, such as description, tags etc. so it would be nice to be able to search across all of these.

Was it helpful?

Solution

I would handle things so that Guide is a document. Categories and Links are embedded inside that document.

A Guide can have a collection of Sub Guides.

The first query is to query all Guides with their subs. You do that like this:

session.Query<Guide>().Include(x=>x.SubGuides).Where(x=>x.Parent == null).ToList();

This will give you it all in one server query.

session.Include<Guide>(x=>x.SubGuides).Load("guides/123")

This will give you a guide with all it subguides.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top