feat(shell-api): support filter arg in sh.listShards() MONGOSH-2500 - #2776
Merged
Conversation
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.
|
Assigned |
nbbeeken
requested review from
nbbeeken
and removed request for
Sgrinfy and
gagik
July 21, 2026 15:03
nbbeeken
requested changes
Jul 21, 2026
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server epic SPM-4275 ("RemoveShard Interface Improvements", debuting in MongoDB 9.0) extends the
listShardscommand to accept an optionalfiltersub-document so callers can, for example, list only the shards that are actively draining:Per the design, only the
drainingflag 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 }.{ listShards: 1 }and behave exactly as before on all server versions.en_USi18n help text and example forsh.listShards.Notes
@serverVersions) sosh.listShards()keeps working everywhere; thefilterfield 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.