Can not connect to the data base using Mongoose 6.0.10
See original GitHub issueHey I recently upgraded to mongoose version 6 and this is how I am establishing the connection but not sure why I am not able to connect to the data base
Can anyone help me what I am doing wrong ?
let { connect, Promise, connection } = require('mongoose');
const { URI } = require("../config")
module.exports = {
init: () => {
const dbOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
autoIndex: false,
family: 4,
connectTimeoutMS: 10000,
auth: {
authSource: ""
},
user: "",
pass: "",
useMongoClient: true
};
connect(
URI,
dbOptions
);
Promise = global.Promise;
connection.on('connected', () => {
console.log('Connected to MongoDB Successfully!');
});
connection.on('err', err => {
console.error(`Error Occured From MongoDB: \n${err.message}`);
});
connection.on('disconnected', () => {
console.warn('Connection Disconnected!');
});
}
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
mongoose - npm
Connecting to MongoDB ... First, we need to define a connection. If your app uses only one database, you should use mongoose.connect ....
Read more >Mongoose v6.8.2: Connecting to MongoDB
You can connect to MongoDB with the mongoose.connect() method. ... This is useful if you are unable to specify a default database in...
Read more >MongoError: auth failed mongoose connection string
I was getting same error. Resolved by adding authSource option to connect function solved the issue. see above code. Share.
Read more >I'm trying to connect mongoDB to my web app but it shows ...
A snippet of code showing how you are creating the connection including your MongoDB connection string with any password or hostname details ...
Read more >Express Tutorial Part 3: Using a Database (with Mongoose)
Installing Mongoose adds all its dependencies, including the MongoDB database driver, but it does not install MongoDB itself. If you want to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are no longer supported options. https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options Try removing those from your options object and see if that fixes it. Also, are any of the event handlers firing?
ok I’ll go ahead and close the issue if you’ve resolved your problem