My objective is to improve data quality in our MongoDB db - by using JSON Schema validation. We are using typescript in our project, and have interfaces for all our collections.
So I'm basically looking for an effective way of;
Converting this interface:
import { ObjectId } from 'mongodb';
export interface Category {
_id: ObjectId;
date: Date;
level: string | null;
}
Into this JSON Schema
export const CategoryJSONSchema = {
required: ['_id', 'date', 'level'],
additionalProperties: false,
properties: {
_id: { bsonType: 'objectId' },
date: { bsonType: 'date' },
level: { oneOf: [{ bsonType: 'null' }, { bsonType: 'string' }] }
}
}