I am building a project with Node.js Express and MongoDB. In my NoSQL database I have a collection called reviews which has 5 documents inserted. When I load my index page I want to retrieve some documents from reviews collection.
require('./database');
const Review = require('./server/models/Review');
// Index view file
app.get('/index', async (req, res) => {
const limitNumber = 8;
const reviews = await Review.find({}).limit(limitNumber);
console.log(reviews) // It retrieves the documents
res.render('index', {"userData": null}, {reviews});
});
When I load http://localhost:3000/index page it seems that it is getting caught in a infinity loop even though I have set my function and query as async-await (which means that find query never ends?)
Note: I am using Mongoose.
Any thoughts?