Friday 2 June 2017

find function is not working in mongoose with specified field

So I am making this website where you can see different recipes for food. When browsing for recipes, I want the user to be able to select a category and browse all the dishes that fall under it (i.e dessert, dinner, vegan etc).

I have this function I created in my router file that returns all the dishes that fall under the specified category:

router.get('/showrecipes/:categoryname', (req, res, next) => {

    let nameQuery = {category: req.params.categoryname};

    Recipe.find(nameQuery, (err, recipes) => {
        if (err) throw err;

        res.json(recipes);
    });
});

However, when I try to test it out in Postman, I keep getting Null instead of all the dishes that fall under the category. enter image description here

All my other functions are correctly working, but this one seems to have issues.



via T-Dot1992

No comments:

Post a Comment