Error while trying to display database data using Handlebars

Asked

Viewed 626 times

-1

Handlebars is returning this error to me every time I access the html page, it receives the values from the database but does not display. I’m using Mongo as a bank. Can you tell me if it’s some version error or if I’m doing something wrong?

" Handlebars: Access has been denied to resolve the Property "name" because it is not an "Own Property" of its Parent. You can add a Runtime option to disable the check or this Warning: See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for Details "

My route

router.get('/categorias', (req,res) => {

    Categoria.find().then((categorias) => {

        res.render('admin/categorias.handlebars',{categorias:categorias});
        console.log(categorias);

    }).catch((err) => {
        req.flash('error_msg',"Houve um erro ao listar as categorias"+err);
        res.redirect('http://localhost:8080/admin');

    });
});

My html page

{{#each categorias}}
    <div class="card mt-4">
        <div class="card-body">
            <h4>Nome: {{name}}</h4>
        </div>
    </div>

{{else}}

{{/each}}

2 answers

1


Answer found.

router.get('/categorias', (req,res) => {

    Categoria.find().sort({date:'desc'}).lean().then((categorias) => {

        res.render('admin/categorias.handlebars',{categorias:categorias});
        console.log(categorias);

    }).catch((err) => {
        req.flash('error_msg',"Houve um erro ao listar as categorias"+err);
        res.redirect('http://localhost:8080/admin');

    });
});

0

router.get('/categorias', (req,res) => {
   
   Categoria.find().map(categories => () {
       const results = {
         name: categories.name,
       }
       return results;
    })

    res.render('admin/categorias.handlebars',{categorias:categorias});
        console.log(categorias);

    }).catch((err) => {
        req.flash('error_msg',"Houve um erro ao listar as categorias"+err);
        res.redirect('http://localhost:8080/admin');

    });
});
  • Friend if possible comment your response and highlight the part that has been modified, this helps other people with the same doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.