• Model.findOneAndUpdate() больше не принимает обратный вызов?

    @sichen
    export const getOne = (req, res) => {
    try {
    const postId = req.params.id

    PostModel.findOneAndUpdate(
    {
    _id: postId,
    },
    {
    $inc: { viewsCount: 1 },
    },
    {
    returnDocument: 'after',
    },
    ).then((post) => {
    if (!post) {
    return res.status(404).json({
    message: 'статьтя не найдена',
    })
    }

    res.json(post)
    })
    } catch (error) {
    console.log(error)
    res.status(500).json({
    messgae: 'не удалось получить статью',
    })
    }
    }
    Ответ написан
    Комментировать