I'm struggling to figure out how to use a MongoDB document's id in the route and manipulate the 'balance' field using Postman. Here's what my code currently looks like:
My route:
router.put('/:id', async (req, res) => {
const id = Account.findById(req.params.id);
const updatedAccount = await Account.findByIdAndUpdate(id,{
firstName: req.body.firstName,
lastName: req.body.lastName,
balance: req.body.balance
});
res.end(JSON.stringify(updatedAccount))
});
My model:
const AccountSchema = new mongoose.Schema({
firstName: {
type: String,
required: true,
},
lastName: {
type: String,
required: true,
},
balance: {
type: String,
required: true
}
}, { collection: 'account'});