Closed eddyystop closed 3 years ago
I remember discussing one version where we do a get
of the old version, performa (deep) merge and then do a normal validation.
That's one option covered in the article. Its a possiblly costly approach.
For mongoDB v3.6, using $jsonSchema
operator will do this job. Internally mongoDB updates/patches the data first, and then validate the updated/patched result. If the result is not valid (according to the previously provided json schema), it will automatically roll back and throw errors.
This is the major reason why I transferred from mongoose to vanilla mongodb.
https://docs.mongodb.com/manual/core/schema-validation/index.html
@beeplin Have you tried this with feathers? Can you give me an idea on how to add this to feathers?
@danlupascu this feature comes from mongodb and has nothing to do with feathers. You don't need to do anything in feathers. Just add json schema in your mongodb collections, and do your create/update/patch in feathers as normal. Mongodb will throw errors if the the written data breaks the schema.
This issue is meant to invite comments.
https://medium.com/@markherhold/validating-json-patch-requests-44ca5981a7fc
These talk about Joi (see eddyystop/feathers-hooks-validate-joi) but the issues are the same. https://github.com/eddyystop/feathers-hooks-validate-joi/issues/5 https://github.com/MarkHerhold/json-patch-joi https://tools.ietf.org/html/rfc6902