I'd like to create a Mongoose Schema that validates the object below with the following restrictions:
- field2 is optional (0-1 relationship),
- field2.type is required if field2 exists (notice that the name of the field is "type" as mongoose reserved word for type definitions),
- field2 and the the base object must be in the same document.
Code example
{
field1: "data",
field2: {
type: "data",
data: "data"
}
}
Thanks in advance.