I've read about validations (validate_doc_update) we can create on CouchDB, however I didn't figure out how I can create them. Can I do it through Fauxton?
Databases -> "mydb" -> Design Documents -> New Doc
Is this the way? Must I declare the function as string? I need an example please (there is any step-by-step in the docs).
Thanks.
Manually writing design documents is an option, you simply need to write it out as a string, since JSON doesn't support writing functions as values. (as you've discovered)
However, I would strongly recommend using other tools to manage your design documents. In particular, the CLI tool couchapp, and related clones (eg: erica) allow you to use a filesystem to represent your design document. (including view functions, validation functions, etc)
Instead of using the fauxton/futon editor (which get clumsy very quickly, especially for non-trivial functions), you can write a plain
.js
file with your validation function, and it can be formatted and uploaded to CouchDB automatically. (the same applies to views, shows/lists, etc)Using this approach is much easier and safer to maintain, and something I highly recommend whenever working with CouchDB.