A
A
Alexey Yakovlev2020-11-01 19:12:56
JavaScript
Alexey Yakovlev, 2020-11-01 19:12:56

Error when searching for products, how to fix?

The form looks like this (pug):

form.header__block-search-content(action="/shop/" method="GET")
       span.header-search-word Поиск
       input.header-search.header-search-show(type="text" name="search")


I process it like this:
router.get('/:title', (req, res) => {
    try {
        const {title} = req.params.title;

        console.log(title);
    } catch (e) {
        res.status(500).json({ message: 'Что-то пошло не так' });
    }
})

Error:
CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model "Product"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-11-01
@yarkov

const {title} = req.params;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question