第二次报这个错了, 一直觉得MongoDB的模型用的type 是 String, 一直报错, 找不到缘由.javascript
// 留言模型1 exports.Comment = mongolass.model('Comment',{ author: {type: Mongolass.Types.ObjectId, require:true}, content: { type: 'String', required: true }, postId: {type: Mongolass.Types.ObjectId, require: true} }) exports.Comment.index({ postId: 1, _id:1 }).exec(); // 经过文章ID获取该文章下全部留言,按留言建立时间升序 exports.Comment = mongolass.model('Comment', { author: { type: Mongolass.Types.ObjectId, required: true }, content: { type: 'string', required: true }, postId: { type: Mongolass.Types.ObjectId, required: true } }) exports.Comment.index({ postId: 1, _id: 1 }).exec()
因为把string 写成了大写的String致使找不到错误的缘由java