You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having an issue when attempting to use a nested schema. For instance:
const Camera = new Schema({
model: {
type: string,
required: true,
}
};
const Room = new Schema({
name: {
type: string,
required: true,
}
camera: {
type: Camera,
required: false
}
};
const roomObj = {
name: "My room",
camera: {
model: "abc123"
}
};
const errors = Room.validate(roomObj);
// ValidationError: camera must be of type [object Object].
If I define the room schema like:
const Room = new Schema({
name: {
type: string,
required: true,
}
camera: Camera
};
const roomObj = {
name: "My room",
camera: {
model: "abc123"
}
};
It works as long as I pass the nested camera object with the required properties, but I get validation errors if the nested camera object is not including in the room object.
Is there a way to have an optional nested schema?
The text was updated successfully, but these errors were encountered:
I'm having an issue when attempting to use a nested schema. For instance:
If I define the room schema like:
It works as long as I pass the nested camera object with the required properties, but I get validation errors if the nested camera object is not including in the room object.
Is there a way to have an optional nested schema?
The text was updated successfully, but these errors were encountered: