node.js - couchdb design views, updating fields on doc creation -


is possible have couch update or change fields on fly when create/update doc? example in design view.... validate_doc_update:

function(newdoc, olddoc, userctx) { } 

within function can throw errors like:

if(!newdoc.user_email && !newdoc.user_name && !newdoc.user_password){     throw({forbidden : 'all fields required'}); } 

my question how reassign field? tried this:

newdoc.user_password ="changed"; 

with changed being new value or hashed value. overall goal build user registration/login system node , couchdb , have not found examples.

the validate_doc_update function cannot have side effects , cannot change document before storage. has power block update or let through. important, because function not called when user requests update, when changes replicated 1 couchdb instance another. function can called multiple times 1 document.

however, couchdb supports document update handlers can modify document or build scratch. these can used convert non-json input data usable documents. can find documentation in couchdb wiki.

before build own user registration/login system, i'd suggest built-in couchdb security features (if haven't - information here). might not enough (e.g. if need email validation or similar), maybe can build on them.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -