# Fix useNewUrlParser Is a Deprecated Option When Upgrading Mongoose

Yes. An agent upgrades Mongoose in its sandbox, drops the connect options the MongoDB driver now warns about, checks the affected queries and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-usenewurlparser-is-a-deprecated-option-warning/mongoose/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads how the app talks to MongoDB. In an Express and React app like sudomaaz/awesomepizza, `db.js` is four lines of interest: `mongoose.connect(process.env.DB_URI, { useUnifiedTopology: true, useNewUrlParser: true })`, then `connected` and `error` listeners on `mongoose.connection` that log a line each. `server.js` requires it, mounts `/api/pizzas/`, `/api/users/` and `/api/orders/`, serves `client/build` when `NODE_ENV` is `production` and listens on port 8000. `package.json` pins `mongoose` at `^5.12.4` with `express`, `stripe`, `uuid`, `router` and `nodemon`, and sets `engines` to Node 15.7.0; the lock file resolves `mongoose` to 5.12.4 on `mongodb` driver 3.6.6. The three models in `models/` call `mongoose.Schema({...})` and `mongoose.model('orders', ...)`, and the routes are all `async` with `await`: `Pizza.find({})`, `findOne({ _id })`, `save()`, `findOneAndDelete({ _id })` and `User.find({ email, password })`. No callback-style query anywhere.

It then measures the upgrade rather than reading about it. `npm install` adds 201 packages; starting the server with the pinned 5.12.4 and an unreachable `DB_URI` prints nothing about the options. After `npm install mongoose@8` (8.24.8 on driver 6.20.0 today), `node server.js` prints two lines before anything else: `[MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version`, and the same for `useUnifiedTopology`, each followed by the `node --trace-warnings` hint. The warning comes from the driver, which is why a 7.8.13 install stays quiet and 8 does not. Deleting the options object from `db.js` makes the 8.x startup silent.

The agent also checks what else moves from 5 to 8 in this code, because the warning is the visible part of a two-major jump. The routes already use promises, so the callback removal in Mongoose 7 touches nothing here, and the agent says so with the grep that proves it. `mongoose.Schema` without `new` still works. The package's own `engines` field now says `node >=16.20.1`, so the `engines` pin of 15.7.0 in `package.json` and the Heroku-era `heroku-postbuild` script are flagged in the pull request as a deploy question, not changed.

Finally it runs what can run without a database: the server starts, the two warnings are gone, and the `error` listener still fires its log line when the URI is unreachable. The `strictQuery` default also moved across the 6 and 7 releases, and the agent names that in the description as the one query behaviour a reviewer should check, since `User.find({ email, password })` filters on fields the schema must declare.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Upgrade mongoose in this repository to the current 8.x and remove the connection options the MongoDB driver now reports as deprecated (useNewUrlParser, useUnifiedTopology, and any others). Read package.json, the lock file, the file that calls mongoose.connect, every model and every route that runs a query first. Start the server with the pinned version and again after the upgrade with an unreachable database URI, and quote the driver warnings the upgrade prints. Remove the options, confirm the startup is clean, and check the rest of the code against the 6, 7 and 8 release changes: callback-style queries, strictQuery, Schema construction and the Node version in engines. Change only what the upgrade requires; flag anything else, like a Node engines pin that is older than the package now supports, in the pull request without changing it. Run any tests and open a pull request that quotes the before and after startup output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that bumps `mongoose` in `package.json` and the lock file and shortens `db.js` to `mongoose.connect(process.env.DB_URI)` with its two listeners. The description quotes the two `[MONGODB DRIVER] Warning:` lines from the 8.x startup before the change and the silent startup after it, lists the grep showing no callback-style query in the routes, and names the `engines` pin and `strictQuery` default as the two things a reviewer decides on.

A reviewer checks that the three models and the routes are untouched, reads the one-line connect call, and decides whether to raise `engines` in the same pull request or a later one. The run's record holds both startup sessions, so the quoted warnings can be opened as the real output rather than taken on trust.

## Run it on every Monday morning

An automation in the Project that holds the repository, with a `schedule` trigger, a `cron` of `0 7 * * 1` and the team's `timezone`, runs this prompt each Monday. A database client that is three majors behind is exactly what a weekly run is for: one week the upgrade and the connect options, the next the `engines` pin once the deploy target is agreed. A run an automation starts has its own `max_runs_per_hour` cap and is not tied to an API key.

From your own scheduler instead, send this body to `POST /o/{org}/sessions` with a `request_id` that is a UUID v5 of the week's date, so a retried job returns the run it already started. The key's `webhook_url` receives `run.completed` or `run.failed` with the session URL when the run ends.

## Why run it on Rush?

The warning is two lines, but knowing whether the rest of the app survives a jump from Mongoose 5 to 8 takes reading every query and starting the app under both versions. The agent does that in its own sandbox, with a fresh `npm install` for each version, and every start and its output is kept in the run's record, so the pull request quotes the driver's own warning text and shows the clean startup after the change rather than asserting it.

It is also work that is easy to put off on a laptop, because it means installing a second major of a package into a working tree and remembering to undo it. On Rush the run starts on a schedule, works in a sandbox that is thrown away afterwards, and leaves a pull request with the evidence attached, and the same prompt runs in every Project whose repository connects with Mongoose the same way.

## Frequently asked questions

### Why does the warning appear only after the upgrade?

It is printed by the MongoDB Node driver, not by Mongoose. Mongoose 5 sits on driver 3, which still read `useNewUrlParser` and `useUnifiedTopology`; Mongoose 8 sits on driver 6, where both options do nothing and are reported as deprecated at connect time. The agent confirms this by starting the app under 5, 7 and 8 with the same options, and only the 8 start prints the lines.

### Will removing the options change how the app connects?

No. The warning text says the options have had no effect since driver version 4, so removing them changes nothing at runtime on the new version. The agent keeps the `connected` and `error` listeners as they are and shows the `error` listener still logging against an unreachable URI.

### What if my routes use callbacks?

Then the upgrade is bigger, because Mongoose 7 removed callback support from queries and the routes would throw. The agent greps for the callback form before deciding; in this repository every route already uses `await`, which it reports. A repository with callbacks gets each one rewritten to `await` in the same pull request, listed by file and line.

### Does it also raise the Node version?

Not on its own. Mongoose 8's package metadata requires Node 16.20.1 or later, and this repository pins `engines` to 15.7.0, so the pull request names the conflict and leaves the decision to the reviewer, since the deploy target is not the agent's call.

## More Mongoose jobs

- [Move a Mongoose API from Travis CI to GitHub Actions](https://getrush.ai/run/migrate-travis-to-github-actions/mongoose/)
- [Upgrade Mongoose 5 to the Current Major in an Express API](https://getrush.ai/run/upgrade-mongoose/mongoose/)
- [Add Account Lockout to a Mongoose and Express App](https://getrush.ai/run/add-account-lockout/mongoose/)

## More jobs like this: Upgrade dependencies weekly

- [Fix "[DEP0044] The util.isArray API Is Deprecated" on Node 22 in NeDB](https://getrush.ai/run/fix-util-isarray-deprecation-warning/nedb/)
- [Fix "Package subpath './v4' is not defined by exports" When Upgrading uuid](https://getrush.ai/run/fix-uuid-deep-require/uuid/)
- [Fix Vulnerable Go Modules in an Echo API](https://getrush.ai/run/fix-vulnerable-dependencies/echo/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
