Iam trying to update a property/ field of a document in couchbase using ottomanjs, while using updateById, updatemany, findOneAndUpdate getting a validation or hook error response , since iam trying to update only one field/property but ottoman expects all propeties of the document while validation and hooks execution and returns obivous error response.
is there a way to update a document in couchbase using ottomanjs only sending that paticular field/ property and skipping hooks and validations which was used implemented for document creation save().
The save() function triggers validate() hooks, because Ottoman has a built-in pre(‘save’) hook that calls validate(). This means that all pre(‘validate’) and post(‘validate’) hooks get called before any pre(‘save’) hooks. The updateById() function have the same behavior.
Hello @Vigneshwaran_Rengana
I think what you are looking for is the implementation of lean
option
https://ottomanjs.com/guides/model.html#use-of-lean
Lean basically suppresses any validation / hooks thats in place.
At present this option is only available for the read model methods.
You may file an issue here Issues · couchbaselabs/node-ottoman · GitHub, this is another great venue to collaborate on Ottoman related questions.
Yeah something like lean, i have filled an issue in GitHub also. i have hooks to check if the user exist before i create them. But while updating user, ottoman execute hooks and since the user exist already returning an error response, even if i remove the hook, ottoman trying to check validation for all fields. Is there any best practice to update a document only sending required fields, or set validation and hooks only for create method?