Hey, thanks for taking time in answering my question ![]()
The schema provided includes just the colors_available property of a major schema (for clarity purposes), if anyone got back to the post later, here is the full schema in case they were interested in it:
{
$jsonSchema: {
bsonType: 'object',
additionalProperties: false,
required: [
'_id',
'brand',
'model',
'price',
'colors_available',
'autopilot'
],
properties: {
_id: {
bsonType: 'objectId'
},
brand: {
bsonType: 'string'
},
model: {
bsonType: 'string'
},
price: {
bsonType: 'decimal'
},
colors_available: {
bsonType: 'array',
items: {
bsonType: 'object',
additionalProperties: false,
uniqueItems: true,
minItems: 1,
required: [
'color',
'stock'
],
properties: {
color: {
bsonType: 'string'
},
stock: {
bsonType: 'int'
}
}
}
},
autopilot: {
bsonType: 'bool'
}
}
}
}
In my case, the error was caused by the typo that you have noticed, in fact, that’s the reason that made my schema break when I tried to remove the squared brackets.
If anyone were interested, here is also a correct example of a document:
{
"_id": {
"$oid": "64f84820853dde3e3c6b10f2"
},
"brand": "Maserati",
"model": "Granturismo",
"price": {
"$numberDecimal": "180000.00"
},
"colors_available": [
{
"color": "Blue",
"stock": 2
},
{
"stock": 4,
"color": "White"
}
],
"autopilot": false
}