Hi there.
My objective is to upgrade an existing mongo database to enforce schemas. Reading this blog, it seems like version 5 actually gives good error messages on insert/update.
But how do I get these error messages for existing data?
This section from compass is to no help (for complex objects that is):
import Ajv from 'ajv';
const ajv = new Ajv({ strict: false });
const validate = ajv.compile(validator.$jsonSchema);
const result = validate(failedDoc);
if (!result) {
docSchemaErrors = validate.errors;
}
@Stennie_X Just tagging you, because I can see in my forum searches that you seem to be the schema validation expert And my AJV workaround does not seem to work well in edge cases
For now I actually found it that the most pragmatic approach is simply to create a temporary collection, enforce schema validation, and then try to insert the document giving errors.
Works surprisingly well, and gives more stable results than using ajv.