How to simulate "reference data" in a document database model?

I am creating a document model of my objects for storage in a document database (RavenDB). Modeling Im Im Models Moving Around Incidents . An incident has a source, priority, category, impact level and many other classification attributes. The RDBMS Id have an incident table with foreign keys in the priority table, category tables, Impacts tables, etc., but I don’t know how to handle this in the document database (this is my first Doc BD).

I have two types of reference data:

  • Simple search values: Countries , States , Sources , Languages . Attributes: they only have a name, but it is a multilingual system, so there is a name for each language. Supported operations: create, delete, rename, deactivate and merge.

  • Sophisticated reference: Same as Simple Lookups plus. Some of them have many fields and have their own business rules and validation rules. For example, two Priorities cannot have the same Rank value. Some of them have a more complex structure, for example Categories consist of Subcategories .

How do I simulate these documents as (or as part of)?


PS: Links to the Document Database Modeling Guide will also be evaluated.

+4
source share
1 answer

Relationships with processing are very different for a document database in an SQL database. The RavenDB documentation describes here . For things that rarely, if ever, change, you should use denormalized reflexes .

In addition, there is a good discussion that basic modeling links are based on the RavenDB file, here . You can extend this example to easily add an abbreviation / name dictionary for the locale. An example of this is here .

To answer your specific questions:

  • You can store the key for each country / state / etc, and then retrieve the locale-specific version using this key by loading the entire reference data document and doing a memory search.
  • Denormalized links would be a good option for categories. You can specify a name and / or parent category if it should be displayed. It seems that the essence itself is small, so you can store all of this (and do not need to denormalize it). It’s normal for it to be replicated - it’s cheaper to process this path, and it will not change, or at least not often (and if possible, you can use corrections to update it). The same applies to your other objects. As far as I can see, business rules have nothing to do with the database, except that you should be able to run the appropriate queries to enforce them.

Update: A post is published here describing how to work with the tree structure in Raven .

+2
source

Source: https://habr.com/ru/post/1397609/


All Articles