2012-07-05 17 views
8

Forse una seconda serie di occhi può vedere ciò che è sbagliato con il mio schemaNodeJS - MongooseJS errore schema che Non riesco a capire

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) 

l'errore:

TypeError: Invalid value for schema path `role` 

risposta

18

Lo schema incorporato (ruoli) deve essere sopra lo UserSchema

+0

grazie mille per la tua risposta .... Trascorro più di 6 ore su questo ... :( – Machete

1

Oltre allo schema dei ruoli che deve essere importato prima dello UserSchema.

Nelle versioni più recenti di mangusta la seguente tipo di sintassi è stato anche necessario per ottenere oltre il '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; 
    }); 

E il genitore:

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

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

Ciò è accaduto quando si passa da mangusta 3 .x a 4.x

Problemi correlati