Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Put request edits not updating object in database but no error either

My database has 'artists' that I can create & delete, but have suddenly lost the ability to edit them. Every other request type works and even when I submit the edit, the routes don't show errors and I'm redirected to the proper page so I suspect it has something to do with my form submission.

I've included my two edit requests below (get and put) from my routes-> artists.js, as well as my delete request since that one is working just fine.

router.get('/:id', catchAsync(async(req, res,) => {
    const artist = await Artist.findById(req.params.id);
    if (!artist) {
        req.flash('error', 'Cannot find that Artist');
        return res.redirect('/artists');
    }
    res.render('artists/show', { artist });
}));

/* artist edits form*/
router.get('/:id/edit', catchAsync(async (req, res) => {
    const artist = await Artist.findById(req.params.id);
    if (!artist) {
        req.flash('error', 'Cannot find that Artist');
        return res.redirect('/artists');
    }
    res.render('artists/edit', { artist }); 
}))

router.put('/:id', catchAsync(async (req, res) => {
    const { id } = req.params;
    const artist = await Artist.findByIdAndUpdate(id, { ...req.body.artist });
    res.redirect(`/artists/${artist._id}`);
}))

Here's the form to update username:

<% layout('layouts/boilerplate')%>
<div class="row">
    <h1 class="text-center">Edit Artist</h1>
    <div class="col-md-6 offset-md-3">
        <form action="/artists/<%=artist._id%>?_method=PUT" method="POST" novalidate class="validated-form"
            enctype="multipart/form-data">
            <div class="mb-3">
                <label class="form-label" for="artist[username]">Title</label>
                <input class="form-control" type="text" id="username" name="username"
                    value="<%= artist.username %>" required>
                <div class="valid-feedback">
                    Looks good!
                </div>
            </div>
            <div class="mb-3">
                <button class="btn btn-primary">Update artist</button>
            </div>
        </form>
        <a href="/artists/<%= artist._id%>">Back To artist</a>
    </div>
</div>

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!