Я пытаюсь использовать mongoose / express для добавления данных формы в БД.Коллекция создается в базе данных, и, хотя при отправке ошибок нет, и мой console.log подтверждает, что там есть данные и сгенерированный идентификатор, у меня все еще нет записей в базе данных, вы можете увидеть, что яотсутствует?Любая помощь будет очень признательна.
**CONFIG**
const port = process.env.PORT || 3000,
bodyparser = require("body-parser"),
mongoose = require("mongoose"),
express = require("express"),
app = express();
app.set("view engine", "ejs");
app.use(
bodyparser.urlencoded({
extended: true
})
);
app.use(
require("express-session")({
secret: "Mama Mia Thats a Spicy Meatball!",
resave: false,
saveUninitialized: false
})
);
app.use(express.static(__dirname + "/styles/"));
app.use(express.static(__dirname + "/Media/"));
app.use(express.static(__dirname + "/JS/"));
mongoose.connect("mongodb://localhost/lashB", {
useNewUrlParser: true
});
const mongCon = mongoose.connection;
mongCon.on("connected", function () {
console.log(`beep boop
database mainframe syncroniiiiiiized`);
});
mongCon.on("disconnected", function () {
console.log(`You're off the database now...Daniel San.`);
});
mongCon.on('error', function () {
console.log(error, `We've got company...there's an error!!!`);
});
**SCHEMA**
var customerSchema = new mongoose.Schema({
firstName: String,
lastName: String,
mobile: String,
email: String,
treatment: String,
time: String,
date: Date
});
var Customer = mongoose.model("Customer", customerSchema, "Customer");
**ROUTES**
app.get("/", function (req, res) {
res.render("main");
});
app.get("/appointment", function (req, res) {
res.render("appointment");
});
app.get("/appointmentConfirmation", function (req, res) {
res.render("appConfirmation");
});
app.get("/blogHome", function (req, res) {
res.render("blogHome");
});
app.post('/appointment', function (req, res) {
var firstName = req.body.firstName,
lastName = req.body.lastName,
mobile = req.body.mobile,
email = req.body.email,
treatment = req.body.treatment,
time = req.body.time,
date = req.body.date;
var deetz = {
date: date,
time: time,
treatment: treatment,
email: email,
mobile: mobile,
firstName: firstName,
lastName: lastName
}
Customer.create(deetz, function (err, info) {
if (err) {
console.log(err, `something went wrong`);
} else {
console.log(info);
console.log('newly created file for a customer');
}
});
res.render('appConfirmation', {
firstName: firstName
}
);
});
app.listen(port, function () {
console.log(`You rockin' now on port ${port}`);
});