Server Discovery And Monitoring engine is deprecated

后端 未结 23 1059
执笔经年
执笔经年 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 00:55

    In mongoDB, they deprecated current server and engine monitoring package, so you need to use new server and engine monitoring package. So you just use

    { useUnifiedTopology:true }

    mongoose.connect("paste db link", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true });
    
    0 讨论(0)
  • 2020-12-01 00:56

    If your code includes createConnetion for some reason (In my case I'm using GridFsStorage), try adding the following to your code:

        options: {
            useUnifiedTopology: true,
        }
    

    just after file, like this:

        const storage = new GridFsStorage({
        url: mongodbUrl,
        file: (req, file) => {
            return new Promise((resolve, reject) => {
                crypto.randomBytes(16, (err, buf) => {
                    if (err) {
                        return reject(err);
                    }
                    const filename = buf.toString('hex') + path.extname(file.originalname);
                    const fileInfo = {
                        filename: filename,
                        bucketName: 'uploads'
                    };
                    resolve(fileInfo);
                });
            });
        },
        options: {
            useUnifiedTopology: true,
        }
    })
    

    If your case looks like mine, this will surely solve your issue. Regards

    0 讨论(0)
  • 2020-12-01 00:56
       const mongo = require('mongodb').MongoClient;
    
       mongo.connect(process.env.DATABASE,{useUnifiedTopology: true, 
       useNewUrlParser: true}, (err, db) => {
          if(err) {
        console.log('Database error: ' + err);
       } else {
        console.log('Successful database connection');
          auth(app, db)
          routes(app, db)
    
       app.listen(process.env.PORT || 3000, () => {
          console.log("Listening on port " + process.env.PORT);
        });  
    

    }});

    0 讨论(0)
  • 2020-12-01 00:58

    Use the following code to avoid that error

    MongoClient.connect(connectionString, {useNewUrlParser: true, useUnifiedTopology: true});
    
    0 讨论(0)
  • 2020-12-01 00:59

    use this line, this worked for me

    mongoose.set('useUnifiedTopology', true);
    
    0 讨论(0)
  • 2020-12-01 01:00

    This solved my problem.

     const url = 'mongodb://localhost:27017';
    
     const client = new MongoClient(url, {useUnifiedTopology: true});
    
    0 讨论(0)
提交回复
热议问题