Answer the question
In order to leave comments, you need to log in
Why doesn't handlebars want to output data from MongoDB?
I did the usual stuff on Nodejs Handlebars and MongoDB.
But when I make a get request on index.hbs I am passing the following parameters from the database:
router.get("/", async (req, res) => {
const todos = await Todo.find({});
res.render("index", {
title: "Todos List",
isIndex: true,
todos
});
});
Server has been started
Handlebars: Access has been denied to resolve the property "completed" 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
Handlebars: Access has been denied to resolve the property "title" 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
[
{
completed: false,
_id: 5ee932ae9c45385520bfb76f,
title: 'Купить мозги',
__v: 0
}
]
<h2>Todos page</h2>
{{#if todos.length}}
<ul>
{{#each todos}}
<li class="todo">
<form action="/complete" method="POST">
<label>
{{#if completed}}
<input type="checkbox" checked />
<span class="completed">{{title}}</span>
{{else}}
<input type="checkbox" />
<span>{{title}}</span>
{{/if}}
<button class="btn btn-small" type="submit">Save</button>
</label>
</form>
</li>
{{/each}}
</ul>
{{else}}
<p>No todos!</p>
{{/if}}
Server has been started
Handlebars: Access has been denied to resolve the property "completed" 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
Handlebars: Access has been denied to resolve the property "title" 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
Answer the question
In order to leave comments, you need to log in
try await Todo.find({}).lean()
mongoose queries return their mongoose objects with a bunch of additional properties, .lean() will return stupid json from the mongo base
https://mongoosejs.com/docs/tutorials/lean.html
I suspect that there mongoos adds some its .completed property
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question