2012-07-05 13 views
8

Może drugi zestaw oczy można zobaczyć, co jest nie tak z moim schemacieNodeJS - MongooseJS błędach schemat, że nie mogę dowiedzieć się,

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) 

Błąd:

TypeError: Invalid value for schema path `role` 

Odpowiedz

18

Wbudowany Schema (Role) musi być powyżej UserSchema

+0

dziękuję za odpowiedź .... spędzam ponad 6h na tym ... :( – Machete

1

Oprócz schematu Roles, który ma zostać zaimportowany przed UserSchema.

W nowszych wersjach mangusta potrzebne było również rodzaj składni dla wyjść poza '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; 
    }); 

i rodzica:

var ParentSchema = new mongoose.Schema({ 
    parentKey: String, 
    someArray: [SomeSchema] 
}) 

module.exports = mongoose.model('Parent', ParentSchema) 

Stało się to podczas przełączania z mangusta 3 .x do 4.x

Powiązane problemy