title: Handlebars: Access has been denied to resolve the property "_id" because it is not an "own property" of its parent
body: <p>I'm new to JS and Handlebars, and would really appreciate some help with a project I'm working on. I'm using AJAX to create a new category, and am trying to then fetch that category back from the server (currently, if I refresh, the new category disappears. I understand AJAX is asynchronous, and am trying to get a response from the server if possible). Currently, I'm getting the following error:</p>
  <p>Handlebars: Access has been denied to resolve the property &quot;_id&quot; because it is not an &quot;own property&quot; of its parent.</p>
  <p>From the reading I've done, I believe this is happening because Handlebars 4.6.0 and on forbids accessing prototype properties and methods of the context object by default. In order to address this, I installed @handlebars/allow-prototype-access package, but I'm not sure how to use it in my app.engine. Could someone please help? Here's my app.js:</p>
  <pre><code>
  const {globalVariables} = require('./config/configuration')
  
  const express = require('express');
  const mongoose = require('mongoose');
  const path = require('path');
  const hbs = require('express-handlebars');
  const {mongoDbUrl, PORT} = require('./config/configuration');
  const flash = require('connect-flash');
  const session = require('express-session');
  const {selectOption} = require('./config/customFunctions');
  const fileUpload = require('express-fileUpload');
  const methodOverride = require('method-override');
  const {allowInsecurePrototypeAccess} = require('@handlebars/allow-prototype-access');
  
  const app = express();
  
  /* Configure Mongoose to Connect MongoDB */
  mongoose.connect(mongoDbUrl, { useNewUrlParser: true })
      .then(response =&gt; {
          console.log(&quot;MongoDB Connected Successfully.&quot;, { useNewUrlParser: true });
      }) .catch(err =&gt; {
          console.log(&quot;Database connection failed&quot;, err)
      });
  
  
  
  /* Configure express*/
  app.use(express.json());
  app.use(express.urlencoded({extended: true}))
  app.use(express.static(path.join(__dirname, 'public')));
  
  /*flash and session*/
  app.use(session({
      secret: 'anysecret',
      saveUninitialized: true,
      resave: true
  }))
  
  app.use(flash());
  
  app.use(globalVariables);
  
  app.use(fileUpload({
      limits: { fileSize: 50 * 1024 * 1024 },
    }));
  
  /* Setup View Engine To Use Handlebars */
  app.engine('handlebars', hbs({defaultLayout: 'default', helpers: {select: selectOption}}));
  app.set('view engine', 'handlebars');
  
  /* Method Override Middleware */
  app.use(methodOverride('newMethod'));
  
  
  /* Routes */
  const defaultRoutes = require('./routes/defaultRoutes');
  const adminRoutes = require('./routes/adminRoutes');
  
  app.use('/', defaultRoutes);
  app.use('/admin', adminRoutes);
  
  app.listen(PORT, () =&gt; {
      console.log(`Server is running on port 3000`);
  })
  </code></pre>
  <p>Here is the .handlebars form I am using to create the category:</p>
  <pre><code> $(&quot;#create-category-button&quot;).on('click', function (e) {
              e.preventDefault();
  
              var data = $(&quot;#category-title&quot;).val();
  
              $.ajax({
                  url: '/admin/category',
                  type: 'POST',
                  data: {name: data},
                  success: function (response) {
  
                      var html = `&lt;tr&gt;
                          &lt;td&gt;${response.title}&lt;/td&gt;
                          &lt;td class=&quot;d-flex justify-content-center&quot;&gt;
                              &lt;a href=&quot;/admin/category/edit/${response._id}&quot; class=&quot;btn btn-sm btn-warning mr-2&quot;&gt;Edit&lt;/a&gt;
                              &lt;form action=&quot;/admin/category/${response._id}?newMethod=DELETE&quot; method=&quot;post&quot;&gt;
                                  &lt;button class=&quot;btn btn-sm btn-danger&quot; type=&quot;submit&quot;&gt;Delete&lt;/button&gt;
                              &lt;/form&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;`;
  
                          console.log(response);
                      $(&quot;.category-list&quot;).append(html);
  
                  }
              });
  
              $(&quot;#category-title&quot;).val('');
          });
  </code></pre>
  <p>Thank you so much in advance for your help!</p>