question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not connect to the data base using Mongoose 6.0.10

See original GitHub issue

Hey 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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
IslandRhythmscommented, Oct 11, 2021

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?

0reactions
IslandRhythmscommented, Oct 11, 2021

ok I’ll go ahead and close the issue if you’ve resolved your problem

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found