Hold DRY with NoSQL

Over the past couple of years, I have been working on projects using NoSQL databases in the publishing industry. As a programmer, and as the person who cut his teeth while developing SQL databases, I try to be dry.

In document-oriented databases, DRY is something like an essay; it can even be detrimental to performance and scalability. Of course, this is the conviction of my colleagues who have worked even for some NoSQL vendors. They must know.

However, I am struggling to take a mental leap because it is difficult for me to learn that DRY and NoSQL are immiscible. So many things in life start with a push too far in one direction and then go along with the compromise that works best.

Data is repeated so often, and I see integrity issues all the time. The relationship with my programmers and ALS is to embrace him, his life. Consuming services must deal with this, or its problem with an upstream team.

I wonder why the documents do not consist of many small subdocuments and are mentioned, stitched together, like the presentation, I think.

The data that is "printed" in each document can only be updated by writing custom "find replace", similar to operations that should work on terabytes. Thus, these functions add value and do not have an explicit need for an Agile story and are not created. Data is becoming more conflicting.

The problem with dividing a document into subdocuments is that the search based on the native database stops working, because it does not know anything about the relationship of the document and the subdocument. Thus, the search should be a custom process that searches for subdocuments and then matches the foreign keys of the main documents with which they are associated.

Is there a middle point or is this really a case of compromise? In fact, it is not easy to find a lot of discussion on this issue.

Luke

+6
source share
1 answer

You do not know what platform you are working on, but have you looked at the layer between the database and the client?

For example, I like feathersjs architecture, which allows you to run hooks before / after database queries. In the context of documents and subdocuments, consider the included populate and dePopulate hooks .

Here is an example of a 1: 1 relationship documentation:

// users like { _id: '111', name: 'John', roleId: '555' } // roles like { _id: '555', permissions: ['foo', bar'] } import { populate } from 'feathers-hooks-common'; const userRoleSchema = { include: { service: 'roles', nameAs: 'role', parentField: 'roleId', childField: '_id' } }; app.service('users').hooks({ after: { all: populate({ schema: userRoleSchema }) } }); // result like // { _id: '111', name: 'John', roleId: '555', // role: { _id: '555', permissions: ['foo', bar'] } } 

PS: feathers support many databases as well as SQL databases .

0
source

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


All Articles