Answer the question
In order to leave comments, you need to log in
How to bind a MongoDB collection to NodeJS?
Hello! I can't figure out what's wrong. Here is app.js code:
var express = require("express");
const MongoClient = require('mongodb').MongoClient;
var app = express();
var url = "mongodb://localhost:27017/dbstudents";
app.set("view engine", "hbs");
app.get("/student/:name", function(request, response) {
var StudentName = request.params.name;
MongoClient.connect(url, function(err, db) {
db.collection("students").findOne({
name: StudentName
}, function(err, student) {
if (err) return res.status(400).send();
console.log(student.telephones);
db.close();
response.render("student.hbs", {
title: student.name,
phonesVisible: true,
group: student.group,
phones: student.telephones
});
});
});
});
app.listen(1000);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question