I am developing a Node JS API but suddently, my MongoDB connection configuration stopped working.
This is how my configuration looks like:
const mongoose = require('mongoose');
try {
mongoose.connect('mongodb+srv://<user>:<password>@hackerrank.jyajn.mongodb.net/<dbname>?retryWrites=true&w=majority', {useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false});
mongoose.Promise = global.Promise;
}
catch(error) {
console.log(error);
}
module.exports = mongoose;
This connection was working until yesterday, but when I tried to run it today it threw the error:
Error: querySrv ENOTFOUND
I saw on this post that
According to MongoDB, SRV is possibly not working due to Mongoose.
So I changed the connection string to the "Node.js 2.2.12 or later" version, as mentioned on the post and it really worked.
My question is, why did this happen? Shouldn't I be able to use the latest connection string, since my node version is v12.17.0?