Several validate_doc_update functions in CouchDB design documents. Any good practices?

After reading this paragraph in the CouchDB Ultimate Guide ( here ):

If you have several project documents, each of which has a validate_doc_update function, all these functions are called with every incoming write request. Only if all of them pass will the recording be successful. The order of verification is not defined. Each verification function must act on its own.

I am wondering if there is good practice to work with multiple validate_doc_update functions?

I mean: is it better to create only one project document with the validate_doc_update field or have a few smaller ones?

In the first case, you can be sure that none of the verification functions will interfere with the other, but the function can become very large if many controls are required.

On the other hand, a few smaller functions may be easier for reading and evolutionary purposes, but everyone should be sure of the purpose of each function and not mess with the others.

Plus, what does it mean that every design document contains a validation function? For example, storing one document in a view seems a little dirty, but creating several project documents just for the intention of having one small validation function does not seem very smart to me.

What do you think?

Maybe I missed something, that is the point of my question, are there any good practices in managing multiple validate_doc_update functions?

+4
source share
2 answers

Notice, I wrote the quoted paragraph.

In general, I see a 1: 1 ratio between applications and projects. All that is required by one application should be in one project document. Large applications may want to rely on several documents for various reasons (for example, different groups of views), but in general, one doc project for each application is a good rule.

You may now have several database applications. For instance. CMS: one application may be publicly accessible, watching the CMS application, and another may be an admin interface. You want them to be different from each other because they are two different applications that work with the same data and save them separately - a good organizational idea. Various security mechanisms are used, so you have two validation functions that implement what is applicable for the respective application.

In the paragraph above, the definition of the case when you have (for any reason) contains more than one project document per database. This explains what to expect. This does not mean that we should leave. Go with one doc design for each application rule, and you feel good most of the time.

+10
source

I know that an answer has already been chosen, but at least I will drink my practice regarding this question as an alternative.

I decided not to build pure CouchApps, at least for the time being. (I decided to use Node.JS as a new middleware layer). Given this, I get much more flexibility from CouchDB Design Documents.

I proceeded to create a separate project document for each object in my database. As a result, each design document contains its own views, validation functions, update handlers, etc. In response to your question, each validation function has only one entity in my database, which makes it more focused and convenient to manage.

+6
source

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


All Articles