Server Discovery And Monitoring engine is deprecated

后端 未结 23 1061
执笔经年
执笔经年 2020-12-01 00:54

I am using Mongoose with my Node.js app and this is my configuration:

mongoose.connect(process.env.MONGO_URI, {
   useNewUrlParser: true,
   useUnifiedTopol         


        
相关标签:
23条回答
  • 2020-12-01 01:13

    I was also facing the same issue:

    1. I made sure to be connected to mongoDB by running the following on the terminal:

      brew services start mongodb-community@4.2
      

      And I got the output:

      Successfully started `mongodb-community`
      

    Instructions for installing mongodb at
    https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ or https://www.youtube.com/watch?v=IGIcrMTtjoU

    1. My configuration was as follows:

      mongoose.connect(config.mongo_uri, {
          useUnifiedTopology: true,
          useNewUrlParser: true})
          .then(() => console.log("Connected to Database"))
          .catch(err => console.error("An error has occured", err));
      

    Which solved my problem!

    0 讨论(0)
  • 2020-12-01 01:14

    I want to add to this thread that it may also have to do with other dependencies.

    For instance, nothing I updated or set for NodeJS, MongoDB or Mongoose were the issue - however - connect-mongodb-session had been updated and starting slinging the same error. The solution, in this case, was to simply rollback the version of connect-mongodb-session from version 2.3.0 to 2.2.0.

    0 讨论(0)
  • 2020-12-01 01:17

    Setting mongoose connect useUnifiedTopology: true option

      import mongoose from 'mongoose';
    
            const server = '127.0.0.1:27017'; // REPLACE WITH YOUR DB SERVER
            const database = 'DBName'; // REPLACE WITH YOUR DB NAME
            class Database {
              constructor() {
                this._connect();
              }
              _connect() {
                mongoose.Promise = global.Promise;
                // * Local DB SERVER *
                mongoose
                  .connect(`mongodb://${server}/${database}`, {
                    useNewUrlParser: true,
                    useCreateIndex: true,
                    useUnifiedTopology: true
                  })
                  .then(
                    () => console.log(`mongoose version: ${mongoose.version}`),
                    console.log('Database connection successful'),
                  )
                  .catch(err => console.error('Database connection error', err));   
              }
            }
            module.exports = new Database();
    
    0 讨论(0)
  • 2020-12-01 01:20

    You Can Try async await

    const connectDB = async () => {
        try {
            await mongoose.connect(<database url>, {
                useNewUrlParser: true,
                useCreateIndex: true,
                useUnifiedTopology: true,
                useFindAndModify: false
            });
            console.log("MongoDB Conected")
        } catch (err) {
            console.error(err.message);
            process.exit(1);
        }
    };

    0 讨论(0)
  • 2020-12-01 01:21
    mongoose.connect("DBURL", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true },(err)=>{
        if(!err){
             console.log('MongoDB connection sucess');
            }
        else{ 
            console.log('connection not established :' + JSON.stringify(err,undefined,2));
        }
    });
    
    0 讨论(0)
提交回复
热议问题