'MongoParseError: options poolsize, usenewurlparse are not supported

I get the error "MongoParseError: options poolsize, usenewurlparse are not supported" when I run "nodemon server".

Here the code for setting up the mongodb connection:

import app from "./server.js"
import mongodb from "mongodb"
import dotenv from "dotenv"

dotenv.config()
const MongoClient = mongodb.MongoClient

const port = process.env.PORT || 8000

MongoClient.connect(
  process.env.RESTREVIEWS_DB_URI,
  {
    poolSize: 50,
    wtimeout: 2500,
    useNewUrlParse: true,
    }
  )
  .catch(err => {
   
    console.error(err.stack)
    process.exit(1)
  })
  .then(async client => {
   
    app.listen(port, () => {
      console.log(`listening on port ${port}`)
    })
  })


Solution 1:[1]

Some of the MongoClient options have been deprecated.

MongoClient.connect(
    process.env.RESTREVIEWS_DB_URI,
    {
        maxPoolSize: 50, 
        wtimeoutMS: 2500,
        useNewUrlParser: true
    }

).catch(err => {
    console.error(err.stack)
    process.exit(1)
}

Solution 2:[2]

The version stopped supporting poolsize,wtimeout and useNewUrlParse.Replace your code with my edit.

import app from "./server.js";
import mongodb from "mongodb"
import dotenv from "dotenv"
dotenv.config()
const MongoClient = mongodb.MongoClient

const port = process.env.PORT || 8000

MongoClient.connect(
    process.env.RESTREVIEWS_DB_URI,
    {
        maxPoolSize:50,
        wtimeoutMS:2500,
        useNewUrlParser:true
    }
)
.catch(err => {
    console.error(err.stack)
    process.exit(1)
})
.then(async client => {
    app.listen(port, () => {
        console.log('listening on port '+port)
    })
})

Solution 3:[3]

const mongoose = require('mongoose');
require('dotenv').config();
const user = process.env.mongoUser;
const pass = process.env.mongoPass;
const url = `mongodb+srv://${user}:${pass}@cluster0.asqnt.mongodb.net/MyDB`;

mongoose.connect(url, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true
})
.then(console.log('connecting'))
.catch(err => console.log(`error: ${err}`))

Solution 4:[4]

After changes in MongoDB-native diver to 4.x, you need to just change MongoClientOptions interface:

you have this:

MongoClient.connect(
  process.env.RESTREVIEWS_DB_URI,
  {
    poolSize: 50, // maxPoolSize
    wtimeout: 2500, // wtimeoutMS
    useNewUrlParse: true, // feel free to remove, no longer used by the driver.
    }
  )

you need:

MongoClient.connect(
  process.env.RESTREVIEWS_DB_URI,
  {
    maxPoolSize: 50,
    wtimeoutMS: 2500,
  }
)

Solution 5:[5]

I had the same issue and this is how I managed, in your code , replace

 {
    poolSize: 50,
    wtimeout: 2500,
    useNewUrlParse: true,
    }

with

{
  
  maxPoolSize: 50,
  wtimeoutMS: 2500,
  useNewUrlParser: true,
}

Solution 6:[6]

use this configuration for mongoose

const express = require('express');
const mongoose = require('mongoose');

mongoose.Promise = global.Promise;
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);
mongoose.connect(your mongodb URI).then(()=> {
    app.listen(PORT, () => {
        console.log(`Listening on port` + PORT);
    })
}).catch((e) => {console.log(e)})

and app.listen is not an asynchronous function you don't need to use async for that

Solution 7:[7]

I was just now trying to get the server up when I noticed that:

{
   useNewUrlParser: true,
   useUnifieldTopology: true,
   useFindAndModify: false
}

They have been deprecated. And looking at this publication the one that has worked is the one from @Jinoy Varghese. I leave you the my code of the mongol congiguration to connect the database.

const mongoose = require('mongoose')
require('dotenv').config({ path: '.env' })

const connectDB = async () => {
    try {
        await mongoose.connect(process.env.DB_MONGO, {
            maxPoolSize: 50,
            wtimeoutMS: 2500,
            useNewUrlParser: true
        })
        console.log('DB connected ')
    } catch (err) {
        console.log(err)
        process.exit(1)
    }
}
module.exports = connectDB

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dillama
Solution 2 Jinoy Varghese
Solution 3 Tyler2P
Solution 4 Denys Pugachov
Solution 5 Netizen_001
Solution 6 kouroshtajalliepour
Solution 7 SerjLafleur