2015-05-25 77 views
1

我正在使用node.js和mongoose编写代码,我在发布材料的问题上陷入困境,材料是我的实体。“路径”无效。必须是字符串或数组mongoose

以下是架构:

new Schema({ 
      title: { 
       type: String, 
       trim: true, 
       set: util.ucfirst, 
       required: true 
      }, 
      description: { 
       type: String, 
       required: true, 
       trim: true 
      }, 
      downloads:{ 
       type: Array, 
       default: [], 
       required: true 
      }, 
      course_id: { 
       type: String, 
       required: false 
      }, 
      _status: { 
       required: false, 
       default: true, 
       type: Boolean, 
       select: false 
      }, 
      created_by:{ 
       type: String 
      }, 
      created_at:{ 
       type: Date, 
       default: Date.now 
      }, 
      modified_by:{ 
       type: String 
      }, 
      modified_at:{ 
       type: Date, 
       default: Date.now 
      } 
     }, 
     { 
      collection: collection, 
      versionKey: true, 
      strict: true 
     }) 

现在用这个数据我张贴,它接受2“串”和1个或多个“文件”数据的样本数据。

以下是帖子的API调用:

exports.post('/', function(req,res,next){ 
    var _error = req.mydata.get('error'); 
    if(!_error){ 
     var _object = req.mydata.get('data') || {}, 
      _files = req.mydata.get('files');  
     _object.downloads = (_files && Array.isArray(_files['upload'])) ? _files['upload'] : (_files && typeof _files['upload'] == "object") ? [_files['upload']] : []; 
     model.insert(_module, _object, function(err, entry){ 
      if(!err && entry){ 
       res.status(200).json(entry); 
       res.end(); 
      }else{ 
       next(); 
      } 
     }); 
    }else{ 
     next(_error); 
    } 
}); 

但是我收到的是下面的输出,这是不预期。 enter image description here

回答

1

我刚碰到同样的问题。您不能将versionKey设置为true,Mongoose认为它是版本密钥的新名称 - 应该是一个字符串。只要省略versionKey参数,你就会好起来的。

我为此打开了一个问题:https://github.com/Automattic/mongoose/issues/3747

相关问题