Hi, how can I achieve following?
db.createCollection("orders", {
validator: {
$jsonSchema: {
bsonType: "object",
required: [ "orderType" ],
properties: {
orderType: {
enum: [ "online", "in-store" ],
description: "must be either 'online' or 'in-store'"
},
shippingAddress: {
$cond: {
if: { $eq: [ "$orderType", "online" ] },
then: { bsonType: "object", required: [ "street", "city", "state", "zip" ] },
else: { bsonType: "object" }
}
},
storeLocation: {
$cond: {
if: { $eq: [ "$orderType", "in-store" ] },
then: { bsonType: "object", required: [ "storeId", "storeName" ] },
else: { bsonType: "object" }
}
}
}
}
}
})