You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行MERN项目代码报错MongoParseError:poolsize、usenewurlparse选项不支持

报错原因

该报错由MongoDB Node.js驱动的版本兼容问题导致:4.0及以上版本的驱动已经移除了旧版本支持的poolSize、useNewUrlParser、wtimeout配置项,传入不被支持的参数就会抛出解析错误。

解决方案

方案1:调整配置适配高版本驱动(推荐)

4.0+版本驱动默认开启useNewUrlParser,无需手动配置,剩余两个参数做对应改名即可:

  • poolSize改为maxPoolSize
  • wtimeout改为wTimeoutMS

修改后的连接代码如下:

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

dotenv.config(); /* configure dotenv */
const MongoClient =
  mongodb.MongoClient; /* get access to MongoClient from MongoDB */
const port = process.env.PORT || 8000; //connect port

//Connect to MongoDB
MongoClient.connect(process.env.RESTREVIEWS_DB_URI, {
  maxPoolSize: 50,
  wTimeoutMS: 2500,
})
  .catch((err) => {
    console.error(err.stack);
    process.exit(1);
  })
  .then(async (client) => {
    //app.listen is used to start our web server, after connecting to the DB
    app.listen(port, () => {
      //we're listening at the port
      console.log(`listening on port ${port}`);
    });
  });

修改完成后直接运行即可正常连接数据库。

方案2:降级驱动到3.x版本

如果不想调整现有代码,直接执行命令安装旧版本稳定驱动即可:
npm install mongodb@3.7.3
该版本完全支持原代码中的所有配置项,无需修改代码即可正常运行。


内容的提问来源于stack exchange,提问作者khalbali_

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 20:48:02