Mongoose version: 4.9.2
Node.js version: 7.7.4
MongoDB Atlas version: 3.2
When trying to connect via mongo shell, everything works fine.
mongo 'mongodb://someUser:[email protected]:27017,someShard-shard-00-01-fjfvq.mongodb.net:27017,someShard-shard-00-02-fjfvq.mongodb.net:27017/someDb?replicaSet=someShard-shard-0&ssl=true&authSource=admin'
Here, I'm connecting to someDb
, but I'm authenticating the user against the admin
database.
When trying to connect with Mongoose I get the following error:
{ MongoError: authentication fail
at Function.MongoError.create ...
I'm thinking it's an error with it not handling the authSource
properly. Mongoose successfully connects if I make admin
the database I'm trying to connect to, but doesn't connect if I make admin
the authSource
I'm trying to authenticate against.
Any ideas?
Same problem here!
Mongoose version: 4.2.10
Node.js version: 6.9.5
MongoDB Atlas version: 3.4.2
When trying to connect via mongo shell, everything works fine, but when I trying from my express.js code, I get the following error:
name: 'MongoError', message: 'no valid seed servers in list'
Has anyone found a solution?
It for some reason works for me now. Can I see your code?
Hello @emaxedon , I am using MEANJS generator from Yeoman. Here is my code:
var config.db.uri = 'mongodb://myUser:[email protected]:27017,myCluster-shard-00-01-67fdt.mongodb.net:27017,myCluster-shard-00-02-67fdt.mongodb.net:27017/myDatabase?ssl=true&replicaSet=myCluster-shard-0&authSource=admin'
`var db = mongoose.connect(config.db.uri, function (err) {
// Log Error
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(err);
} else {
// Enabling mongoose debug mode if required
mongoose.set('debug', config.db.debug);
// Call callback FN
if (cb) cb(db);
}
});`
It returns the following error:
Could not connect to MongoDB!
{ MongoError: no valid seed servers in list}
Using this same String, I can successfully connect via mongo shell. Until I find a solution, I'm using an old database from Xervo.io, but my actual database is already set in Atlas. Any ideas ?
@emaxedon did you change anything between when it was working and when it started working? And is it still working?
@gilalan @varunjayaraman
Not sure if it makes a difference - but the only thing I changed that made it work (no idea why this works) is the following.
const db = mongoose.connect(config.db.uri, {
server: {
socketOptions: {
keepAlive: 1
}
}
}).connection;
db.on('error', (err) => {
console.log(err);
});
db.once('open', (err) => {
if (err) {
console.log(err);
} else {
// ...
}
});
Not changed for me =( i'm stucked with that error.
Anyway @emaxedon, thanks for your help!
I had the same issue like @gilalan. "name: 'MongoError', message: 'no valid seed servers in list'". I updated node to version v6.10.3 and mongoose to version 4.9.8. After these updates I was able to connect to Atlas via Mongoose.
@gilalan I can confirm that mongoose 4.2.10 cannot connect to MongoDB Atlas with the error message MongoError: no valid seed servers in list
.
However, I can also confirm that upgrading to the latest mongoose (currently 4.9.8) fixed the issue, and enabled mongoose to connect to MongoDB Atlas.
I believe this issue should be closed.
It is fixed now! I don't know why but it's ok!.
Most helpful comment
Hello @emaxedon , I am using MEANJS generator from Yeoman. Here is my code:
var config.db.uri = 'mongodb://myUser:[email protected]:27017,myCluster-shard-00-01-67fdt.mongodb.net:27017,myCluster-shard-00-02-67fdt.mongodb.net:27017/myDatabase?ssl=true&replicaSet=myCluster-shard-0&authSource=admin'
`var db = mongoose.connect(config.db.uri, function (err) {
// Log Error
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(err);
} else {
});`
It returns the following error:
Could not connect to MongoDB! { MongoError: no valid seed servers in list}
Using this same String, I can successfully connect via mongo shell. Until I find a solution, I'm using an old database from Xervo.io, but my actual database is already set in Atlas. Any ideas ?