2016-06-18 3 views
0

캐스팅 오류가 ObjectId입니다. 문서의 제목을 찾기 위해 노력하고 있습니다.mongoose 객체 ID 오류 발견

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

var contentSchema = new Schema({  
    language: String, 
    genres : String, 
    title : { 
     type: [String], 
     required: true 
    }, 
    cast : {name : [String]} , 
    storyline : String, 
    videoUrl : String, 
    path : String, 
    contentType : String, 
    duration : String, 
    rating : String, 
    tvCardImageUrl : String, 
    tvBgImageUrl : String, 
    mobileCardImageUrl : String, 
    mobileImageUrl : String, 
    tabletCardImageUrl : String, 
    tabletBgImageUrl : String, 
    publishedDate : Date, 
    uploadedDate : Date, 
}); 

module.exports=mongoose.model('contents',contentSchema); 

router.route('/content/card').get(function(req, res){ 
    Content.find({language: 'English'}) 
    .select('title') 
    .exec(function(err, content){ 
     if(err) 
      res.send(err); 
     res.json(content); 
    }); 

}); 

오류

"message": "Cast to ObjectId failed for value \"card\" at path \"_id\"", 
"name": "CastError", 
"kind": "ObjectId", 
"value": "card", 
"path": "_id" 

당신은 나를 어떻게 반환 캐스팅 ObjectId가 알려 주시기 바랍니다 수 있습니까?

+0

추가 _id : 스키마 파일의 문자열이 여전히 작동하지 않습니다. – user3401694

+0

null 객체가 반환되었습니다. – user3401694

+0

@JohnnyHK String으로 변경된 후 작동했습니다. 내 나쁜 내가 worg ID를 넘겨받은 이유는 null 객체를 반환하기 때문입니다. 조니, 고마워. – user3401694

답변

0

_id"card" 인 문서가 컬렉션에있는 것 같습니다. 이 값을 ObjectId으로 변환하면 오류가 발생합니다.

문서의 _id 값이 문자열 (기본값 인 ObjectId과 반대) 인 경우 스키마에 지정해야합니다. 그렇다면 _id: String을 스키마에 추가하십시오.

관련 문제