I am currently working on a home collection validation project that involves different room types (double, single, ensuite). The validation process should allow for the addition of all the listed room types.
"rooms.type": {bsonType: ["ensuite", "double", "single"]},
This is the validation schema that I have implemented:
db.createCollection("home", {
validator : {
$jsonSchema : {
bsonType: "object",
required: ["address.line1", "address.town", "rooms.type",
"rooms.qty", "rooms.price"],
properties: {
"address.line1": {bsonType: "string"},
"address.town": {bsonType: "string"},
"rooms.type": {bsonType: ["ensuite", "double", "single"]},
"rooms.qty": {bsonType: "int", minimum: 0},
"rooms.price": {bsonType: ["double"], minimum: 0},
}}}})
However, I encountered an error:
"ok" : 0,
"errmsg" : "Unknown type name alias: ensuite",
"code" : 2,
"codeName" : "BadValue"
I am looking to resolve this issue and ensure that the array room.type can accommodate any one or all attributes within the specified group in the schema.