List MongoDB data in a handlebars file
-
Hi everyone, Im tryingto to list the data coming from the mongo db in a file handlebars. But the problem is that when I load the screen, only the message "Category Listing" appears and the names of the categories do not appear as requested: {{#each erros}}
{{texto}}
{{else}} {{/each}} To create the modell and the collection, I used: var conexao = require("../config/conexao") var CategoriaSchema = conexao.Schema({ nome:{ type: String, require: true }, slug:{ type: String, require: true }, date:{ type: Date, default: Date.now() } }) module.exports = conexao.model("Categorias", CategoriaSchema) And in the main file, to render the handlebars file, I used: const express = require("express"); const handlebars = require("express-handlebars"); const app = express(); const Handlebars = require('handlebars') const Categorias = require("./models/Categoria")
app.get("/", (req, res) =>{
Categorias.find().then((categorias) =>{
res.render("listaCategorias", {categorias: Categorias})
}).catch((erro) => {
(colsole.log(erro))
res.redirect("/cadastrar")
})
})Can anybody help me?
-
Hi everyone, Im tryingto to list the data coming from the mongo db in a file handlebars. But the problem is that when I load the screen, only the message "Category Listing" appears and the names of the categories do not appear as requested: {{#each erros}}
{{texto}}
{{else}} {{/each}} To create the modell and the collection, I used: var conexao = require("../config/conexao") var CategoriaSchema = conexao.Schema({ nome:{ type: String, require: true }, slug:{ type: String, require: true }, date:{ type: Date, default: Date.now() } }) module.exports = conexao.model("Categorias", CategoriaSchema) And in the main file, to render the handlebars file, I used: const express = require("express"); const handlebars = require("express-handlebars"); const app = express(); const Handlebars = require('handlebars') const Categorias = require("./models/Categoria")
app.get("/", (req, res) =>{
Categorias.find().then((categorias) =>{
res.render("listaCategorias", {categorias: Categorias})
}).catch((erro) => {
(colsole.log(erro))
res.redirect("/cadastrar")
})
})Can anybody help me?
Bárbara 2023 wrote:
Can anybody help me?
No. This area isn't for technical queries, as it says at the top of the page. Try posting it here: Ask a Question[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Hi everyone, Im tryingto to list the data coming from the mongo db in a file handlebars. But the problem is that when I load the screen, only the message "Category Listing" appears and the names of the categories do not appear as requested: {{#each erros}}
{{texto}}
{{else}} {{/each}} To create the modell and the collection, I used: var conexao = require("../config/conexao") var CategoriaSchema = conexao.Schema({ nome:{ type: String, require: true }, slug:{ type: String, require: true }, date:{ type: Date, default: Date.now() } }) module.exports = conexao.model("Categorias", CategoriaSchema) And in the main file, to render the handlebars file, I used: const express = require("express"); const handlebars = require("express-handlebars"); const app = express(); const Handlebars = require('handlebars') const Categorias = require("./models/Categoria")
app.get("/", (req, res) =>{
Categorias.find().then((categorias) =>{
res.render("listaCategorias", {categorias: Categorias})
}).catch((erro) => {
(colsole.log(erro))
res.redirect("/cadastrar")
})
})Can anybody help me?