in my company schema i have a posted job which is type array and will hold subdocuments
companySchema.js
PostedJobs : [{
JobName : { type: String, required : true},
JobType : { type: String, required : true},
JobLocation : { type: String, required : true},
JobSalay: { type: String, required : true}
}],
in my /company route i get all company registered by specific user through Creatorentity in model
to get that user company i use
router.get('/', isLoggedIn , function(req, res, next) {
Company.find({'Creator': req.user.id}).then(function(companies) {
res.render('Company', { "Companies" : companies });
});
});
after getting company i want to visit a specific company page on clicking company name(unique)
router.get('/:name' , isLoggedIn , function(req , res , next) {
var name = req.params.name;
Company.findOne({Name : name}).then(function(Company) {
res.render('dashboard',{
"Company" : Company,
errors : []
});
})
});
now i want to post a job to this specific company from a POST route as my req.body consist of JobName , JobType , JobLocation and JobSalary which i have assigned to a specific variable now how should i push this doc to array
POST route
router.post('/:name' , isLoggedIn , function(req , res , next) {
var JobName = req.body.JobName;
var JobType = req.body.JobType;
var JobLocation = req.body.JobLocation;
var Salary = req.body.Salary;
//push this job to that specific comapny
});