{"id":487,"hash":"0171f1765767c797dadabb06cfe48cdbba1f13ad556069406d4aae700b48a71a","pattern":"Avoid &quot;current URL string parser is deprecated&quot; warning by setting useNewUrlParser to true","full_message":"I have a database wrapper class that establishes a connection to some MongoDB instance:\n\nasync connect(connectionString: string): Promise<void> {\n        this.client = await MongoClient.connect(connectionString)\n        this.db = this.client.db()\n}\n\nThis gave me a warning:\n\n  (node:4833) 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.\n\nThe connect() method accepts a MongoClientOptions instance as second argument. But it doesn't have a property called useNewUrlParser. I also tried to set those property in the connection string like this: mongodb://127.0.0.1/my-db?useNewUrlParser=true but it has no effect on those warning. \n\nSo how can I set useNewUrlParser to remove those warning? This is important to me since the script should run as cron and those warnings result in trash-mail spam. \n\nI'm using mongodb driver in version 3.1.0-beta4 with corresponding @types/mongodb package in 3.0.18. Both of them are the latest avaliable using npm install.\n\nWorkaround\n\nUsing an older version of mongodb driver:\n\n\"mongodb\": \"~3.0.8\",\n\"@types/mongodb\": \"~3.0.18\"","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"Check your mongo version:\n\nmongo --version\n\nIf you are using version >= 3.1.0, change your mongo connection file to ->\n\nMongoClient.connect(\"mongodb://localhost:27017/YourDB\", { useNewUrlParser: true })\n\nor your mongoose connection file to ->\n\nmongoose.connect(\"mongodb://localhost:27017/YourDB\", { useNewUrlParser: true });\n\nIdeally, it's a version 4 feature, but v3.1.0 and above are supporting it too. Check out MongoDB GitHub  for details.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/50448272/avoid-current-url-string-parser-is-deprecated-warning-by-setting-usenewurlpars","votes":283,"created_at":"2026-04-19T04:51:14.646487+00:00","updated_at":"2026-04-19T04:51:30.401681+00:00"}