I have this client schema that has a reference to a progress schema. I keep getting an error when I run the code. I think my syntax is wrong in the validation method, but not sure of the correct syntax for validate reference documents...any ideas??
Error:
UnhandledPromiseRejectionWarning: Error: Schema can only contain plain objects
const clientSchema = new Schema(
{
name: {
type: String,
},
contactDetails: contactSchema,
addressDetails: addressSchema,
clientGoals: {
type: String,
},
progressUpdates: [
{
type: Schema.Types.ObjectId,
ref: "Progress",
},
],
},
{
// Define collection name
collection: "clients",
}
);
const Client = mongoose.model("Client", clientSchema);
// Validation using Joi
function validateClient(client) {
const schema = Joi.object({
name: Joi.string().min(3).required(),
contactDetails: {
email: Joi.string().required(),
contactNumber: Joi.string().required(),
},
addressDetails: {
number: Joi.number().integer().required(),
street: Joi.string().required(),
city: Joi.string().required(),
},
clientGoals: Joi.string().min(5).required(),
progressUpdates: Joi.array().items(
Joi.object().keys(progressSchema).required()
),
});
return schema.validate(client);
}
progressSchema
const progressSchema = new mongoose.Schema(
{
content: {
type: String,
},
client: {
type: Schema.Types.ObjectId,
ref: "Client",
},
},
{
// Define collection name
collection: "progress",
}
);