21

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}`)
    })
  })
Pink
  • 223
  • 1
  • 2
  • 5

8 Answers8

26

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)
}
Dillama
  • 260
  • 2
  • 4
9

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)
    })
})
Jinoy Varghese
  • 169
  • 1
  • 9
6

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,
  }
)
Denys Pugachov
  • 360
  • 1
  • 4
  • 9
3

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,
}
2
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}`))
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Umar
  • 49
  • 2
  • 3
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Tyler2P Aug 27 '21 at 11:23
1

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
0

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

0

poolSize, wtimeout, and useNewUrlParse is deprecated. Replace with maxPoolSize, wtimeoutMS, and useNewUrlParser. Your code won't work without it.