database – Node.js + Mongoose retrieve document 1st time ok, if reloads the page, they don’t
My route file:
const { Router } = require("express")
const productController = require("../controllers/productController")
const router = Router()
router.get("/product/show/:id", productController.show)
The controller:
const Product = require("../models/Product")
const product = await Product.findById({ _id: req.params.id })
try {
res.render("products", { product })
}
catch(error) {
console.log(error)
}
The call from view:
<button onclick="window.location.href="https://stackoverflow.com/product/show/<%= product._id%>"">Show</button>
The first time it renders the page products and showing the product from database just fine, with all ok on url (localhost:3000/product/show/13141150254335) but if I reload the page, it takes forever and finnaly shows a blank page. The console error doesn’t help much, it show a huge text from mongoose (a object about models, etc). Anyone can tell me what’s going on here?
Read more here: Source link
