# Fix "DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7"

Yes. An agent checks every query filter against its schema, sets strictQuery to the value that keeps results identical, and shows the warning gone.

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

## What the agent does

The agent reads the models before the warning, because the right value of the option depends on what the queries filter on. In a bot like savioxavier/discord-neofetch, `commands/neoconf.js` defines two schemas, `distroChoiceSchema` with `userId` and `distroChoice` and `promptChoiceSchema` with `userId` and `promptChoice`, and exports the `DistroConfig` and `PromptConfig` models. Every query in the repository is a `findOne({ userId: ... })`: two in `neoconf.js`, four in `neofetch.js` and four in `neomobile.js`. `index.js` connects with `await mongoose.connect(MONGODB_URI)` inside a try block that logs the error.

Then it works out which install prints the warning. `package.json` declares `"mongoose": "^6.1.9"` and the lock file pins 6.1.9, so `npm ci` installs 6.1.9 and prints nothing. `npm update mongoose` moves to 6.13.12, the newest release the range allows, and starting the bot with any `MONGODB_URI` prints `(node:…) [MONGOOSE] DeprecationWarning: Mongoose: the strictQuery option will be switched back to false by default in Mongoose 7. Use mongoose.set('strictQuery', false); if you want to prepare for this change. Or use mongoose.set('strictQuery', true); to suppress this warning.` before the connection is even attempted; it prints with an unreachable server too. Installing releases one at a time shows 6.7.0 silent and 6.8.0 the first to warn, from `lib/helpers/printStrictQueryWarning.js`, which `lib/index.js` calls when the option was never set.

The option decides whether a filter on a field the schema does not define is kept or stripped, so the agent compares the filters with the schemas. All ten queries filter on `userId`, which both schemas define, so `true` and `false` return the same documents here. The agent picks `false`, the value Mongoose 7 and later use and the one the warning itself suggests for preparing, and adds `mongoose.set('strictQuery', false);` in `index.js` before the `connect` call, with a one-line comment naming the schemas it checked.

Proof is the start-up output. With the line in place, starting the bot against an unreachable `MONGODB_URI` prints only the connection error from the catch block and no deprecation line. The agent also notes what it did not do: `npm outdated` shows Mongoose 9.12.0 as latest, and a major upgrade, which removes callbacks and changes other defaults, is a separate change. The lock file update to 6.13.12 is included only if the team asked for it; otherwise the pull request adds the one line, which is harmless on 6.1.9 and removes the warning the day the lock moves.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Our Node service prints \"DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7\" on start-up. Read every schema and every query filter in the repository, and say which Mongoose version the lock file installs, which version the declared range would move to, and which release first prints the warning. Decide whether strictQuery true or false returns the same documents for our filters, set it explicitly before connect with a comment naming what you checked, and start the service against an unreachable database URI before and after to show the warning gone. Open a pull request with both start-up outputs, and leave any major upgrade of Mongoose out of it.",
  "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

A pull request that adds one line and one comment to `index.js` above `mongoose.connect`. The description lists the two schemas with their fields, the ten `findOne` filters with their files and lines, the version facts (6.1.9 locked, 6.13.12 reachable, 6.8.0 first to warn, 9.12.0 latest), and the start-up output before and after.

A reviewer checks that the chosen value matches the filters: every query uses a schema field, so either value is safe and `false` is the one later majors default to. They also see that `package.json` and the lock file are unchanged unless the pull request says otherwise.

The description names the major upgrade as separate work and the `engines` field, which still says Node 16, as another, so the pull request stays one line.

## Run it on every Dependabot pull request

The warning arrives with a dependency bump, so the natural moment is the pull request that bumps it. A pull request Dependabot opens comes from a bot sender, which never fires an automation's `github` trigger, so a handler on your server receives GitHub's `pull_request` webhook for the bump and starts this run with `POST /o/{org}/sessions`, naming the pull request in `resources` and sending a UUID v5 of the pull request number as `request_id`, so a redelivered webhook returns the run already started; the run pushes the one-line fix to the bump's branch when the start-up output shows a Mongoose deprecation.

For many services at once, your server sends this request once per repository, each with its own UUID as `request_id` so a retry returns the run already started, and reads each `run.completed` webhook; a key starts at most `max_concurrent` runs at a time and queues the rest.

## Why run it on Rush?

The warning text offers two values and the right one depends on reading every query, which is tedious by hand and easy to get wrong. In a Rush sandbox the agent lists the schemas and filters, installs several Mongoose releases to find where the warning starts, and keeps every start-up log, so the pull request argues from the repository's own queries rather than from a blog post.

A deprecation fix should not smuggle in a major upgrade. The agent reports the latest major and the lock file state and leaves both alone, so the reviewer reads a one-line change with its reasoning and the larger upgrade stays a decision for the team.

## Frequently asked questions

### Should I set strictQuery to true or false?

Check your filters. If every filter uses fields the schema defines, both values return the same documents and `false` matches what Mongoose 7 and later default to. If a filter uses a field outside the schema, `true` strips it and `false` keeps it, and that difference is a behaviour change to review.

### Why does npm ci not print the warning but npm update does?

The lock file pins 6.1.9, which predates the warning. The declared range `^6.1.9` allows any 6.x, and `npm update` moves to 6.13.12, which prints it. The agent installs releases to find that 6.8.0 is the first that does.

### Does upgrading to Mongoose 7 or later remove the warning?

Yes, 8.x prints nothing and defaults `strictQuery` to false. That is a major upgrade with other breaking changes, so the pull request sets the option explicitly and names the upgrade as separate work.

### Will the one-line fix do anything on the locked 6.1.9?

It sets an option that 6.1.9 already supports and changes nothing for filters on schema fields. The day the lock file moves past 6.8.0, the warning is already handled.

## More Mongoose jobs

- [Fix "MongoParseError: options usecreateindex, usefindandmodify are not supported" in Mongoose 6 and Later](https://getrush.ai/run/fix-mongoose-usecreateindex-not-supported/mongoose/)
- [Fix useNewUrlParser Is a Deprecated Option When Upgrading Mongoose](https://getrush.ai/run/fix-usenewurlparser-is-a-deprecated-option-warning/mongoose/)
- [Move a Mongoose API from Travis CI to GitHub Actions](https://getrush.ai/run/migrate-travis-to-github-actions/mongoose/)

## More jobs like this: Fix a bug from an alert

- [Fix Alembic Multiple Heads After a Merge](https://getrush.ai/run/fix-multiple-heads/alembic/)
- [Fix "OSError: mysql_config not found" When Installing a Flask App's Requirements](https://getrush.ai/run/fix-mysql-config-not-found/mysqlclient/)
- [Fix Call to Undefined Function mysql_connect() on PHP 7 and PHP 8](https://getrush.ai/run/fix-mysql-connect-function-removed/php/)

## 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/)
