Server Discovery And Monitoring engine is deprecated

后端 未结 23 1062
执笔经年
执笔经年 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:09

    i had the same errors popping up each time and this worked for me

    mongoose.connect("mongodb://localhost:27017/${yourDB}", {
        useNewUrlParser: true,
        useUnifiedTopology: true
    
    }, function (err) {
        if (err) {
            console.log(err)
        } else {
            console.log("Database connection successful")
        }
    });
    
    0 讨论(0)
  • 2020-12-01 01:10
    mongoose.connect('mongodb://localhost:27017/Tododb', { useNewUrlParser: true, useUnifiedTopology: true });
    

    Will remove following errors:-

    (node:7481) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

    (node:7481) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

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

    This worked for me

    For folks using MongoClient try this:

    MongoClient.connect(connectionurl, 
      {useUnifiedTopology: true, useNewUrlParser: true},  callback() {
    

    For mongoose:

    mongoose.connect(connectionurl, 
             {useUnifiedTopology: true, useNewUrlParser: true}).then(()=>{
    

    Remove other connectionOptions

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

    Add the useUnifiedTopology option and set it to true.

    Set other 3 configuration of the mongoose.connect options which will deal with other remaining DeprecationWarning.

    This configuration works for me!

    const url = 'mongodb://localhost:27017/db_name';
    mongoose.connect(
        url, 
        { 
            useNewUrlParser: true, 
            useUnifiedTopology: true,
            useCreateIndex: true,
            useFindAndModify: false
        }
    )
    

    This will solve 4 DeprecationWarning.

    1. Current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
    2. Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
    3. Collection.ensureIndex is deprecated. Use createIndexes instead.
    4. DeprecationWarning: Mongoose: findOneAndUpdate() and findOneAndDelete() without the useFindAndModify option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#-findandmodify-.

    Hope it helps.

    0 讨论(0)
  • 2020-12-01 01:12
    const mongoose = require("mongoose");
    
    mongoose.connect('mongodb://localhost:27017/Edureka',{ useNewUrlParser: true, useUnifiedTopology: true }, (error)=> {
        const connectionStatus = !error ? 'Success': 'Error Connecting to database';
        console.log(connectionStatus);
    });
    
    0 讨论(0)
  • 2020-12-01 01:12

    if you used typescript add config to the MongoOptions

    const MongoOptions: MongoClientOptions = {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    };
    
          const client = await MongoClient.connect(url, MongoOptions);
    
    if you not used typescript  
    const MongoOptions= {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    };
    
    0 讨论(0)
提交回复
热议问题