Reputation: 570
I'm always connecting to the "admin" DB, which is a fixed bug.
Using Mongoose 5.0.6 MongoDb 3.6 and trying to connect to Atlas.
Cheers
Upvotes: 21
Views: 27429
Reputation: 703
Just a side note if you ever get an error connecting to the MongoDB Atlas make sure:
And if all fails
Goodluck!
Upvotes: 2
Reputation: 899
Basically you should try connecting with your url link, and specify the DB name on the mongoose connect method so if your cluster link is:
mongodb+srv://userName:[email protected]/
and your DB name is:
testDB
then you should call the mongoose.connect method as follows:
mongoose.connect('mongodb+srv://userName:[email protected]/', {dbName: 'testDB'});
Upvotes: 65
Reputation: 41
Connection is established when you use this connection string for (MongoShell 3.6+) :
var connDB = "mongodb+srv://<username>:<password>@cluster-fax0w.mongodb.net/test"
However, you will not be able to read/write data without entering the DBName in the mongoose.connect().
mongoose.connect(uri, { dbName: <your DB name> })
.then( () => {
console.log('Connection to the Atlas Cluster is successful!')
})
.catch( (err) => console.error(err));
Upvotes: 4