Search code examples
express-handlebars

express-handlebars unable to print Object content ,


express-handlebars

exports.All_category = async (req,res)=>{
var categories = await Category.find({},{"date":0, '__v':0})
.then(result=> {
    console.log(result);
    res.render('category', { title: 'Category', cate: 'active',result });

})

I want to Print only name and id but its printing full Objects

This is the result i an getting


Solution

  • You are printing the whole object because the model.find({}); method returns an object to result which you print afterwards.

    So if you want to only print the id and the name then you should instead write:

    console.log('Id: ' + result._id + ' Name: ' + result.name);