I want to be able to update a specific posts data inside my mongoDB using the object id. I have already created a html form where the fields get populated with the selected post data. I can then change these values and submit the form data to http://localhost:5000/update-opportunity. In my backend I then wait for a form submission on this url. This where I am stuck I don't know how to use the id I sent with axios to update a specific object in the database.
Heres my code;
axois form submission in vue component
axios.post('http://localhost:5000/update-opportunity', {
id: this.id,
company_name: this.company_name,
company_type: this.company_type,
lines_of_business: this.lines_of_business,
client_type: this.client_type,
contract_type: this.contract_type,
contact_name: this.contact_name,
contact_number: this.contact_number,
email_address: this.email_address,
opportunity_owner: this.opportunity_owner,
decision_maker: this.decision_maker,
annual_jobs: this.annual_jobs,
average_fee: this.average_fee,
annual_value: this.annual_value,
next_steps: this.next_steps,
due_date: this.due_date
})
.then((response) => {
console.log(response);
this.$emit('formSubmitted');
})
.catch(function (error) {
console.log(error);
});
backend form submission
router.post('/update-opportunity', (req, res, next) => {
const db = getDb();
db
.collection('jobs')
.insertOne({
company_name: req.body.company_name,
company_type: req.body.company_type,
lines_of_business: req.body.lines_of_business,
client_type: req.body.client_type,
contract_type: req.body.contract_type,
contact_name: req.body.contact_name,
contact_number: req.body.contact_number,
email_address: req.body.email_address,
opportunity_owner: req.body.opportunity_owner,
decision_maker: req.body.decision_maker,
annual_jobs: req.body.annual_jobs,
average_fee: req.body.average_fee,
annual_value: req.body.annual_value,
next_steps: req.body.next_steps,
due_date: req.body.due_date,
date_added: new Date()
})
.then(result => {
res.status(201).send();
console.log(result);
})
.catch(err => {
console.log(err);
});
});
getDb() is just my database connection