与. Mongoose.js
_node.js
我有这个架构:
var Photo = new Schema({
URL:String
,description:String
,created_by:{type:ObjectId, ref:'User'}
,created_at:{type:Date, default:Date.now()}
});
var User = new Schema({
name:{type:String,index:true}
,email:{type:String,index:true, unique:true}
});
//Task model
var Task = new Schema({
title:String
,created_by:{type:ObjectId, ref: 'User'}
,created:{type:Date, default:Date.now()}
,responses:[{
type:Number
,user:{type:ObjectId, ref: 'User'}
,comment:String
,avatarURL:String
,photo:{type:ObjectId, ref: 'Photo'}
,created:{type:Date, default:Date.now()}
}]
});
//Group model
var Group = new Schema({
name:String
,tasks:[Task]
});
并且此代码出错(组很好,idx 处的任务很好,响应是一个空数组,用户有效,照片有效):
var typePhoto = 6;
var resp = {
type: typePhoto//photo
,user: user._id
,photo: photo._id
};
group.tasks[taskIdx].responses.push(resp); //errors out here
那时我收到以下错误:
/home/admin/notitws/node_modules/mongoose/lib/utils.js:434
throw err;
^
CastError: Cast to number failed for value "[object Object]" at path "undefined"
at SchemaNumber.cast (/home/admin/notitws/node_modules/mongoose/lib/schema/number.js:127:9)
at Array.MongooseArray._cast (/home/admin/notitws/node_modules/mongoose/lib/types/array.js:78:15)
at Object.map (native)
at Array.MongooseArray.push (/home/admin/notitws/node_modules/mongoose/lib/types/array.js:187:23)
at exports.taskAddPhoto (/home/admin/notitws/routes/group.js:1097:35)
at Promise.exports.createPhoto (/home/admin/notitws/routes/photos.js:106:4)
at Promise.addBack (/home/admin/notitws/node_modules/mongoose/lib/promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (/home/admin/notitws/node_modules/mongoose/lib/promise.js:66:38)
at Promise.complete (/home/admin/notitws/node_modules/mongoose/lib/promise.js:77:20)
有关如何解决此问题或可能导致此问题的任何想法?
PS不知道这是否重要,但在我正在填充tasks.responses.user
和获取组的呼叫tasks.responses.photo
中tasks.created_by
。