Sharding Collection Discovery for MongoDB 6.0+ Compatibility and RBAC Stability#185
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the getMongoData Mongo shell script to better report sharding metadata on MongoDB 6.0+ clusters and to reduce failures/noise under restricted RBAC by skipping certain internal collections during data collection.
Changes:
- Adjust sharded database detection to treat
partitioned: undefined(MongoDB 6.0+) as eligible for sharding collection discovery. - Expand collection filtering in
printDataInfoto skip additional internal collections that commonly trigger authorization errors. - Bump script version from
4.1.1to4.1.2.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactor collection filtering logic to simplify checks for system collections and replication metadata.
Comment on lines
+567
to
+573
| // Filter MongoDB-internal replication metadata collections, but ONLY | ||
| // in the "local" database, to avoid dropping legitimate user | ||
| // collections (e.g., app.replsetEvents, app.startup_log_archive) | ||
| // that happen to share a similar name in user databases. | ||
| if (mydb.name === "local") { | ||
| if (name === "startup_log" || name.startsWith("replset.")) { | ||
| return; |
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.
Summary
This PR introduces two critical improvements to
getMongoData.js:Feature 1: Fix Sharding Collection Discovery for MongoDB 6.0+
Problem
In MongoDB 6.0+, the
partitionedfield was removed from theconfig.databasescollection. The legacy logic usedif (db.partitioned)to gate collection discovery. Since this field is nowundefined, the script incorrectly skips sharding information for modern clusters, leading to empty reports.Solution
Updated the conditional check to
if (db.partitioned !== false). This remains inclusive ofundefined(modern) andtrue(legacy) while still respecting explicitfalseflags from older versions.Compatibility Matrix
partitionedvaluedb.partitioned !== falsetruetruefalsefalseundefinedtrueFeature 2: Harden Collection Discovery Against Authorization Errors
Problem
When running with restricted RBAC (Role-Based Access Control), the script often encounters "Unauthorized" errors when trying to access internal logs (e.g.,
local.startup_log) or replica set metadata. These errors can cause the script to terminate prematurely or produce noisy, invalid JSON output.Solution
Expanded the collection exclusion list in
printDataInfo. In addition tosystem.*, the script now explicitly skips:replicaset*startup_log*replset*Code Changes Summary
File:
getMongoData.jsVerification
partitionedfield is absent.