Hi All,

I'm writing a validate_doc_update function at the moment. I want to validate that document inserts comply with a strict schema. I have been thinking of how to do this, without making the validate function too inefficient.

Since there is no way to pass parameters to the validate_doc_update function, I was thinking of fetching the schema (contained in a local JSON file) asynchronously. This could be a terrible idea. However, I've found that I can request the schema once and then store it. So, there would be one initial performance hit in fetching the file, and from then on it would be saved. See the example function:
/
//function validate(new_doc, old_doc, userCtx){//
//   if(typeof this.schema == 'undefined')//{//
//        // get the schema//
//   }//
//   // make sure new_doc conforms to the this.schema[new_doc.type]//
//}/

I'm just wondering, is there a better way to do this? Are there any compelling reasons not to do this?

Also, I have considered just including the schema statically in the function but the solution above is preferable as the schema changes often and I don't want to have to update the design functions.

Thanks

Conor

Reply via email to