2016-11-20 55 views
0

如何將數據插入貓鼬嵌套對象中?我不斷收到我的ref集合沒有定義的錯誤!這裏是我的代碼,我正在嘗試將數據插入到address對象和companyId將數據插入到Mongoose嵌套對象

var companySchema = new Schema({ 
company_Id :{ 
    type : Schema.Types.ObjectId, 
    ref : recruiter, 
    optional : true 
},  
address : { 
    country : { 
     type : String, 
     required : true 
    }, 
    city :{ 
    type : String, 
    required : true 
    }, 
    street: { 
    type : String, 
    required : true 
    } 
} 
+0

你應該閱讀文檔: http://mongoosejs.com/docs/models.html – Marcs

回答

0

您正在使用的,而不是編譯型號名稱
變量試試這個

var recruiterSchema = new Schema({ 
    // some fields 
}) 

mongoose.model("Recruiter", recruiterSchema); // same model name here 

var companySchema = new Schema({ 
    company_Id :{ 
     type : Schema.Types.ObjectId, 
     ref : "Recruiter" // and here 
    } 
    // some fields 
}) 

mongoose.model("Company", companySchema); 
+0

是的,我做了完全一樣的事情,但我有一個錯誤消息,招聘人員沒有定義。 – Ray