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}`)
})
})
What version of Mongoose are you using? The useCreateIndex option has been deprecated for a while and removed as of the Mongoose 6 release per No More Deprecation Warning Options: useNewUrlParser , useUnifiedTopology , useFindAndModify , and useCreateIndex are no longer supported options.
The error is because of the new version of the mongoose i.e version 6.0. 6. useNewUrlParser , useUnifiedTopology , useFindAndModify , and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser , useUnifiedTopology , and useCreateIndex are true , and useFindAndModify is false .
How to use it. The unified topology is available now behind the useUnifiedTopology feature flag. You can opt in to using it by passing the option to your MongoClient constructor: const client = MongoClient('mongodb://localhost:27017', { useUnifiedTopology: true });
useNewUrlParser : The underlying MongoDB driver has deprecated their current connection string parser. Because this is a major change, they added the useNewUrlParser flag to allow users to fall back to the old parser if they find a bug in the new parser.
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)
}
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)
})
})
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}`))
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,
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With