How do I make a PUT request with express and Postman in order to change a given MongoDB field?

I recommend you to split up the operations(find at first, then update, then save) Try something like this in callback of your put handler:

const updates = Object.keys(req.body)
try {
        const account = await Account.findById(
        updates.forEach((update) => account[update] = req.body[update])
        if (!account) {
            return res.status(404).send()
    } catch (e) {

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top