Maybe a second set of eyes can see what is wrong with my schema
var UserSchema = new Schema({
name:
{
first : {type: String}
, last : {type : String}
}
, password: {type: String}
, username: {type: String}
, role: RoleSchema
, created_at : {type : Date, default : Date.now}
, modified_at : {type : Date, default : Date.now}
})
var RoleSchema = {
type: [String]
, study_type: [String]
}
mongoose.model('User', UserSchema)
The Error:
TypeError: Invalid value for schema path `role`
The embedded Schema (Roles) needs to be above the UserSchema
In addition to the Roles schema having to be imported before the UserSchema.
In the newer versions of mongoose the following sort of syntax was also needed for to get beyond the 'TypeError: Invalid value for schema Array path
:
var SomeSchema = new mongoose.Schema();
SomeSchema.add({
key1: {
type: String,
required: true
},
key2: {
type: String,
required: true
},
key3: {
type: String,
required: true
}
});
SomeSchema.get(function(val){
// Remove the _id from the Violations
delete val._id;
return val;
});
And the parent:
var ParentSchema = new mongoose.Schema({
parentKey: String,
someArray: [SomeSchema]
})
module.exports = mongoose.model('Parent', ParentSchema)
This happened when switching from mongoose 3.x to 4.x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With