Skip to content

feat(shell-api): support filter arg in sh.listShards() MONGOSH-2500 - #2776

Merged
ivandevp merged 2 commits into
mainfrom
MONGOSH-2500-listshards-filter
Jul 22, 2026
Merged

feat(shell-api): support filter arg in sh.listShards() MONGOSH-2500#2776
ivandevp merged 2 commits into
mainfrom
MONGOSH-2500-listshards-filter

Conversation

@ivandevp

Copy link
Copy Markdown
Collaborator

Server epic SPM-4275 ("RemoveShard Interface Improvements", debuting in MongoDB 9.0) extends the listShards command to accept an optional filter sub-document so callers can, for example, list only the shards that are actively draining:

db.adminCommand({ listShards: 1, filter: { draining: true } })

Per the design, only the draining flag is respected in the filter.

This PR surfaces that capability in the sh.listShards() shell helper, which previously always issued a bare { listShards: 1 }.

Changes

  • sh.listShards(filter?) now accepts an optional filter document. The filter is validated as an object and passed through to the server as { listShards: 1, filter }.
  • A filter is only added to the command when it is non-empty, so existing no-arg calls remain byte-for-byte { listShards: 1 } and behave exactly as before on all server versions.
  • Updated the en_US i18n help text and example for sh.listShards.
  • Added unit tests covering filter pass-through and the empty-filter case.

Notes

  • The helper is intentionally left ungated (no @serverVersions) so sh.listShards() keeps working everywhere; the filter field is only sent when a caller explicitly passes one. On < 9.0 servers a supplied filter should be rejected server-side rather than guarded on the client.

Extend the listShards helper to accept an optional filter document,
passed through to the server as { listShards: 1, filter } (server 9.0+,
SPM-4275). Only a non-empty filter is sent, so no-arg calls remain
{ listShards: 1 }. Updates i18n help text/example and adds unit tests.
@ivandevp
ivandevp requested a review from a team as a code owner July 21, 2026 12:00
@ivandevp
ivandevp requested a review from Sgrinfy July 21, 2026 12:00
@codeowners-service-app
codeowners-service-app Bot requested a review from gagik July 21, 2026 12:05
@codeowners-service-app

Copy link
Copy Markdown

Assigned gagik for team mongosh-developers because Sgrinfy is out of office.

@nbbeeken
nbbeeken requested review from nbbeeken and removed request for Sgrinfy and gagik July 21, 2026 15:03
Comment thread packages/shell-api/src/shard.ts
Comment thread packages/shell-api/src/shard.spec.ts Outdated
…ONGOSH-2500

Address review feedback: drop the {} default so an omitted filter is
genuinely undefined, and gate on truthiness (if (filter)) instead of
key count. An explicitly-passed empty object now sends filter: {};
an omitted arg still sends bare { listShards: 1 }. Add a test covering
the explicit empty-filter case.
@ivandevp
ivandevp requested a review from nbbeeken July 21, 2026 19:19

@nbbeeken nbbeeken left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful!

@ivandevp
ivandevp merged commit bc5383b into main Jul 22, 2026
151 of 155 checks passed
@ivandevp
ivandevp deleted the MONGOSH-2500-listshards-filter branch July 22, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants