After reading this paragraph in the CouchDB Definitive Guide (here):
If you have multiple design documents, each with a validate_doc_update function, all of those functions are called upon each incoming write request. Only if all of them pass does the write succeed. The order of the validation execution is not defined. Each validation function must act on its own.
I'm wondering if there is any good practice to deal with multiple validate_doc_update function ?
I mean: Is it better to create only one design document with a validate_doc_update field or having several smaller ones?
In the first case, one can be sure that none of the validation functions will interfere with another, but the function may become very large if a lot of controls are needed.
On the other side, several smaller functions may be easier for reading purposes and evolutions, but one have to be sure of the purpose of each function and not mess with other ones.
Plus, what's the point of letting each design document hold a validate function? Storing one in a view document seems a bit dirty for instance, but creating several design documents just for the intent of holding one small validation function doesn't seems very clever to me either.
What do you think?
I may have missed something, that's the point of my question, is there any good practices about the management of multiple validate_doc_update function?
Note, I wrote the quoted paragraph.
In general, I'm seeing a 1:1 correlation between applications and design docs. Everything a single application needs should be in one design document. Bigger applications may want to rely on multiple design docs for various reasons (like different groups of views), but in general, one design doc per app is a good rule of thumb.
Now, you may have multiple applications per database. E.g. a CMS: one application could be the public facing CMS viewing app and another one would be the admin interface. You want to keep them separate because, well, they are two distinct apps that operate on the same data and keeping them separate is a good organisational idea. Different security mechanisms apply, so you have two validation functions that do implement what is applicable for the respective app.
The quoted paragraphis the definition of the case where you do have (for whatever reason) have more than one design document per database. It explains what to expect. It is not meant as a guideline how to split things up. Go with the one design doc per app rule of thumb and you're good most of the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With