I am busy creating a project which allows the user to enter "Email" & "Password" to register to the site,
When I try to enter a user using the "Email" & "Password" to enter this site, I get the following error:
MongooseError: Operation users.insertOne() buffering timed out after 10000ms
Unhandled rejection MongooseError: Operation users.findOne() buffering timed out after 10000ms
I have tried all the proposed solutions I found here which have a similar problem, delete the node_modules folder and reinstall mongoose.
Please see my code below, thanks!
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mongoose = require("mongoose");
const app = express();
app.use(express.static("public"));
app.set('view engine', 'ejs');
app.use( bodyParser.urlencoded ({extended: true}));
mongoose.connect = ("mongodb://localhost:27017/userDB", {useNewUrlParser: true, useUnifiedTopology: true});
const userSchema = {
email: String,
password: String
};
const User = new mongoose.model("User", userSchema);
app.get("/", function(req, res){
res.render("home")
});
app.get("/login", function(req, res){
res.render("login")
});
app.get("/register", function(req, res){
res.render("register")
});
app.post("/register", function(req, res){
const newUser = new User({
email: req.body.username,
password: req.body.password
});
newUser.save(function(err){
if (err) {
console.log(err);
} else {
res.render("secrets");
}
});
});
Can anyone help me out?