Handlebars: Access has been denied to resolve the property "from" because it is not an "own property" of its parent Handlebars: Access has been denied to resolve the property "from" because it is not an "own property" of its parent express express

Handlebars: Access has been denied to resolve the property "from" because it is not an "own property" of its parent


If using mongoose, this issue can be solved by using .lean() to get a json object (instead of a mongoose one):

dbName.find({}).lean()  // execute query  .exec(function(error, body) {     //Some code  });


i solve this issue by installing a dev dependency for handlebars

npm i -D handlebars@4.5.0


Today I have the same warning from handlebars and the view is empty. Below is how I fixed that:

//  * USERS PAGE// @description        users route// @returns           ../views/users.hbsrouter.get('/users', async (req, res) => {  // get all items from db collection  const collection = 'User'  await dbFindAllDocs(collection) // <=> wrapper for Model.find() ...    .then(documents => {      // create context Object with 'usersDocuments' key      const context = {        usersDocuments: documents.map(document => {          return {            name: document.name,            location: document.location          }        })      }      // rendering usersDocuments from context Object      res.render('users', {        usersDocuments: context.usersDocuments      })    })    .catch(error => res.status(500).send(error))})

the users.hbs file

<ul>{{#each usersDocuments}}<li>name: {{this.name}} location: {{this.location}}</li>{{/each}}    </ul>

Creating an entire new Object named context with its own properties then pass in it into the render function will fix the issue...

note:

When we do not create a new Object, it is easy to accidentally expose confidential information, or information that could compromise the security of the projet, mapping the data that's returned from the database and passing only what's needed onto the view could be a good practice...