내 파일에 대한 스키마를 생성하고 아래와 같이 호출했지만 스키마에 주석이 등록되지 않았다는 오류가 발생했습니다 ....... 이는 경로 때문입니까?몽구스에서 스키마를 등록하고 호출하는 방법
내 스키마,
var mongoose = require('mongoose'),
path = require('path'),
config = require(path.resolve('./config/config')),
Schema = mongoose.Schema;
var Commentsscheme = new Schema({
articleid: {
type: Schema.ObjectId
},
fromuser: {
type: String
},
touser: {
type: String
},
comment: {
type: String
}
});
mongoose.model('comments', Commentsscheme);
내 JS,
var path = require('path'),
mongoose = require('mongoose'),
passport = require('passport'),
Comments = mongoose.model('comments');
/* ------ Inserting a comment ------ */
exports.insertcomment = function (req, res) {
var comments = new Comments(req.body);
console.log(comments)
comments.status = 1;
var data = {};
comments.save(function (err,resl) {
if (err) {
console.log(err);
return err;
}
data = { status: false, error_code: 0, message: 'Unable to insert' };
if (resl) {
data = { status: true, error_code: 0,result: resl, message: 'Inserted successfully' };
}
res.json(data);
});
};
나는 내 파일과 아래를 호출하기위한 스키마를 생성하지만 스키마가 의견 등록되지 않는다는 오류를 말한다 .... .... 어느 누구도 도움을 제안 할 수 있습니다 ........................
다음과 같이이 스키마를 사용하는 파일 comment.js입니다 ............ – MMR
업데이트 된 코드를 게시하십시오. – Sachin
Sachin, – MMR