the problem seems to be with mongoose & mongodb packages as it works fine when
mongoose.connect('mongodb+srv://mydb:<password>@cluster0.w1opr.mongodb.net/test?retryWrites=true&w=majority');
is removed it also works fine on repl.it cloud env here is my code
var express = require('express');
var ejs = require('ejs');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
mongoose.connect('mongodb+srv://mydb:<password>@cluster0.w1opr.mongodb.net/test?
retryWrites=true&w=majority');
app.set('view engine','ejs')
app.use(bodyParser.urlencoded({extended: true}));
.
.
.
app.listen(3000,function(){
console.log('Server is running on port 3000');
});
Actually mongoose 6 requires Node 12 or higher, so this is expected behavior. Mongoose 6 does not support Node 10.So updating Node version will fix the issue. It also fix the problem by downgrading mongoose version to 5.
Check your node version, if it's lower than 12 it won't work, if that's the case updating node should do do the job. You could downgrade your mongoose version too.
There's an issue closed on Mongoose github page. https://github.com/Automattic/mongoose/issues/10638
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With