2016-10-27 3 views
4

이상한 일이 있습니다. 나는 몇 몽구스 모델을 가지고 - 그 중 하나 (하나의!)에서이 오류가 얻을 : 나는 아주 이상한 내가 여러 작업 스키마를 가지고 찾을 수mongoose TypeError : 스키마가 생성자가 아닙니다.

TypeError: Schema is not a constructor 

합니다. 내가 작동하지 않는 스키마에 mongoose.Schema 로깅을 시도하고 실제로 내 작업 스키마에서 mongoose.Schema 다릅니다 - 어떻게 그게 가능 한가? 코드는 거의 동일합니다. 다음은 작동하지 않는 스키마에 대한 코드는 다음과 같습니다 작업 스키마

var mongoose = require('mongoose'); 
var Schema = mongoose.Schema; 

var errSchema = new Schema({ 
    name: String, 
    images:[{ 
    type:String 
    }], 
    sizes:[{ 
    type: String 
    }], 
    colors:[{ 
    type: Schema.ObjectId, 
    ref: 'Color' 
    }], 
    frontColors:[{ 
    type: Schema.ObjectId, 
    ref: 'Color' 
    }], 
    script: Boolean 
},{ 
    timestamps: true 
}); 

var Err = mongoose.model('Err', errSchema); 

module.exports = Err; 

코드 :

var mongoose = require('mongoose'); 
var Schema = mongoose.Schema; 

var colorSchema = new Schema({ 
    name: String, 
    image: String, 
    rgb: String, 
    comment: String, 
}); 

var Color = mongoose.model('Color', colorSchema); 

module.exports = Color; 

어떤 도움을 주시면 감사하겠습니다!

+0

이하로 사용하여 생성자 문제를 해결해야! 이봐, 바보 같은 기분이야! 신속한 회신에 감사드립니다. 대답을하고 그것을 받아 들일 것입니다 :) –

+0

나는이 오류를 어떻게 해결 했습니까? – vashishth

+0

@vashishth - 내 문제는'Schema.Types.ObjectId'의 누락 된'Types'에서 왔습니다. 일단 내가 이것을 추가하면, 내 문제는 사라졌다. –

답변

8

나는 같은 일을 발생했습니다. 나는이

var mongoose = require('mongoose'); 
    var Schema = mongoose.Schema(); 
    var schema = new Schema({ 
     path : {type:string , required:true}, 
     title: {type:string , required: true} 
    }) 
module.export = mongoose.model('game', schema); 

같은 이전 코드가 그럼 난 스크립트

물론
var mongoose = require('mongoose'); 
    var schema = mongoose.Schema({ 
     path : {type:string , required:true}, 
     title: {type:string , required: true} 
    }) 
module.export = mongoose.model('game', schema); 
관련 문제