Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. List MongoDB data in a handlebars file

List MongoDB data in a handlebars file

Scheduled Pinned Locked Moved The Lounge
databasemongodbhelpxmlquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Barbara 2023
    wrote on last edited by
    #1

    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?

    OriginalGriffO J 2 Replies Last reply
    0
    • B Barbara 2023

      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?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "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

      1 Reply Last reply
      0
      • B Barbara 2023

        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?

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        This would be a database question and there is a database forum. Use code tags when you post code and anything else that should be formatted.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups