I try to get the validation bsonType recursively for a single field at a time in order to perform some conversion before sending the data into db.
For example I have this jsonSchema validation:
{
"validator": {
"$jsonSchema": {
"bsonType": "object",
"required": [
"address"
],
"properties": {
"address": {
"bsonType": "string",
"description": "required address as string"
},
"accessDates": {
"bsonType": "array",
"items": {
"bsonType": "object",
"properties": {
"accessDate": {
"bsonType": "date",
"description": "access date"
}
}
}
}
}
}
},
"validationLevel": "moderate",
"validationAction": "error"
}
This is not a real world example, I created it this way to add extra complexity. Now, let’s say I want to insert the following data:
{
"address": "some address",
"accessDates": [
{"accessDate": "2021-01-01"}.
{"accessDate": "2021-01-02"}
]
}
The question is how can I get bsonTypes for the following:
address,
accessDates,
accessDates[].accessDate
Or, is there any other way to convert json to bson before inserting intot DB?