I am using Mongoose with my Node.js app and this is my configuration:
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopol
In mongoDB, they deprecated current server and engine monitoring package, so you need to use new server and engine monitoring package. So you just use
{ useUnifiedTopology:true }
mongoose.connect("paste db link", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true });
If your code includes createConnetion for some reason (In my case I'm using GridFsStorage), try adding the following to your code:
options: {
useUnifiedTopology: true,
}
just after file, like this:
const storage = new GridFsStorage({
url: mongodbUrl,
file: (req, file) => {
return new Promise((resolve, reject) => {
crypto.randomBytes(16, (err, buf) => {
if (err) {
return reject(err);
}
const filename = buf.toString('hex') + path.extname(file.originalname);
const fileInfo = {
filename: filename,
bucketName: 'uploads'
};
resolve(fileInfo);
});
});
},
options: {
useUnifiedTopology: true,
}
})
If your case looks like mine, this will surely solve your issue. Regards
const mongo = require('mongodb').MongoClient;
mongo.connect(process.env.DATABASE,{useUnifiedTopology: true,
useNewUrlParser: true}, (err, db) => {
if(err) {
console.log('Database error: ' + err);
} else {
console.log('Successful database connection');
auth(app, db)
routes(app, db)
app.listen(process.env.PORT || 3000, () => {
console.log("Listening on port " + process.env.PORT);
});
}});
Use the following code to avoid that error
MongoClient.connect(connectionString, {useNewUrlParser: true, useUnifiedTopology: true});
use this line, this worked for me
mongoose.set('useUnifiedTopology', true);
This solved my problem.
const url = 'mongodb://localhost:27017';
const client = new MongoClient(url, {useUnifiedTopology: true});