获得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?
答案 0 :(得分:0)
您的收藏中似乎有一个_id
"card"
的文档。该值无法转换为导致错误的ObjectId
。
如果您的文档“_id
值是字符串(与默认的ObjectId
相对),则需要在架构中指定它。如果是,请将_id: String
添加到您的架构中。