I have created a collection in my MongoDB database called joblist
. I have also created a schema of DB called jobList.js
var mongoose = require('mongoose');
const joblistSchema = mongoose.Schema({
companyTitle: String,
jobTitle: String,
location: String,
});
const JlSchema = module.exports = mongoose.model('JlSchema',joblistSchema,'joblist');
This is route folder users.js
where I'm using my routes
const jobList = require('../models/jobList');
//post joblist
router.post('/appliedjobs', function(req,res) {
console.log('posting');
jobList.create({
companyTitle: req.body.companyTitle,
jobTitle: req.body.jobTitle,
location: req.body.location
},function(err,list) {
if (err) {
console.log('err getting list '+ err);
} else {
res.json(list);
}
}
);
});
//getting joblistlist
router.get('/appliedjobs',function(req,res) {
console.log('getting list');
jobList.find(function(err,list) {
if(err) {
res.send(err);
} else {
res.json(list);
}
});
});
I have inserted some data in database manually(by using mongodb cmd).I can get them by GET
method from
but when I'm trying to post
some data using postman I'm getting error as
posting
TypeError: Cannot read property 'companyTitle' of undefined at D:\product\project-1\routes\users.js:115:28 at Layer.handle [as handle_request] (D:\product\project-1\node_modules\express\lib\router\layer.js:95:5) at next (D:\product\project-1\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\product\project-1\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\product\project-1\node_modules\express\lib\router\layer.js:95:5) at D:\product\project-1\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\product\project-1\node_modules\express\lib\router\index.js:335:12) at next (D:\product\project-1\node_modules\express\lib\router\index.js:275:10) at D:\product\project-1\routes\users.js:15:3 at Layer.handle [as handle_request] (D:\product\project-1\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\product\project-1\node_modules\express\lib\router\index.js:317:13) at D:\product\project-1\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\product\project-1\node_modules\express\lib\router\index.js:335:12) at next (D:\product\project-1\node_modules\express\lib\router\index.js:275:10) at Function.handle (D:\product\project-1\node_modules\express\lib\router\index.js:174:3) at router (D:\product\project-1\node_modules\express\lib\router\index.js:47:12)
I don't know what's wrong in my code. can anyone help? I want get and post data to collection called joblist
.
Cannot read property 'companyType' of undefined
I don't seecompanyType
anywhere but the title? – CertainPerformancebody
inreq.body
is undefined – Adelin