mongoose查找objectId大小写错误

时间:2016-06-18 17:05:26

标签: mongodb casting mongoose find

获得ObjectId投射错误。试图找到内容的文档标题。

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?

1 个答案:

答案 0 :(得分:0)

您的收藏中似乎有一个_id "card"的文档。该值无法转换为导致错误的ObjectId

如果您的文档“_id值是字符串(与默认的ObjectId相对),则需要在架构中指定它。如果是,请将_id: String添加到您的架构中。