我正在尝试在mongodb中创建一个嵌套模式,如下所示,但它在插入值时给出了范围错误:
var UserInfo = new Schema({
userName : {type : String, required: true, index:{unique:true}},
password : {type : String, required: true},
country : {type : String, required: true},
city : {type : String , required: true},
profileImage :{type: String, required:true},
});
var StatusUpdate= new Schema({
status : {type: String},
user : [UserInfo],
likers : {type: Array, def :[]}
});
我在post请求中发送用户名,然后如果找到用户,我将用户对象插入statusUpdate架构。但这里它给了我范围错误。
var user = mongoose.model('UserInfo');
user.findOne({userName: req.param('username')},function(e,o){
if(e)
callback('not found');
else
{
statusUpdate.collection.insert({status: req.param('status'), user : o}, function(e,o)
{
console.log(e);
if(e)
callback('unable to update status')
else
callback(o)
});
}
});