我有一个看起来像这样的集合:
{
"_id": "5c90e8736441c96cc8e5c703",
"meta": {
"schemaVersion": 1,
"locHint": {
"region": "150",
"country": "GBR"
}
},
"name": "My test study"
}
Run Code Online (Sandbox Code Playgroud)
和以下验证器:
{
"$jsonSchema": {
"bsonType": "object",
"required": [
"meta.schemaVersion"
"meta.locHint.region",
"meta.locHint.country",
"name"
],
"properties": {
"meta.schemaVersion": {
"bsonType": "int",
"description": "Version counter used schema changes"
},
"meta.locHint.region": {
"bsonType": "string",
"pattern": "^[0-9]{3}$",
"description": "meta.locHint.region is required to be a valid iso3166 region (3 digits)"
},
"meta.locHint.country": {
"bsonType": "string",
"pattern": "^[A-Z]{3}$",
"description": "meta.locHint.country is required to be a valid …Run Code Online (Sandbox Code Playgroud)