Mongoose, CastError: Cast to Array failed for value when trying to save a model that contains a model

Man, I had a similar issue creating an Schema like this:

QuestionnaireSchema = mongoose.Schema({
    formId: Number,
    name: String,
    questions: [
        {
            type: String,
            title: String,
            alternatives:[{
                label: String,
                value: "Mixed"
            }]
        }
    ]
});

My mistake was that I am using “type” as a field name and this is reserved word in mongoose.

I just change:

type: String,

to

formType: String,

and that works.

see: https://github.com/Automattic/mongoose/issues/1760

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)