Mongodb stats - #8
Merged
Merged
Conversation
Replace regex-based URI manipulation with Uri.parse() and uri.replace() to correctly handle database path replacement. This fixes the bug where \ was interpreted as a literal string instead of a regex capture group, causing errors like 'Could not connect to admin\'. - mongodb_connection.dart: Use Uri.parse() in listDatabases() and listCollections() - mongodb_service.dart: Use Uri.parse() in executeCommand(), find(), and aggregate() - Preserves query parameters (authSource, replicaSet, ssl) when replacing database
Create MongoStatsView widget that displays MongoDB server statistics in a card-based UI similar to RedisView. Features: - Auto-refresh every 3 seconds - Summary chips (Version, Uptime, Connections, Queries) - Memory, Operations, Connections, Network cards - Server, Storage, Replication, WiredTiger sections - Safe connection management with proper cleanup on dispose
Update workspace_panel to display MongoStatsView instead of MongoDatabasesView when a MongoDB connection is selected, providing server statistics similar to Redis connections.
Add unit tests to verify correct database path replacement in MongoDB URIs: - Replaces database in URI without existing database - Replaces database in URI with existing database - Preserves query parameters (authSource, replicaSet, ssl) - Handles various URI formats (with/without auth, custom ports, connection strings) - Ensures no literal \ appears in final URI (the bug we fixed)
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.
Changelog
[Unreleased]
Added
MongoDB Statistics View: Added MongoStatsView widget that displays MongoDB server statistics in a card-based UI, similar to Redis stats view
Auto-refreshes server statistics every 3 seconds
Summary chips showing Version, Uptime, Connections, and Queries
Detailed cards for Memory, Operations, Connections, and Network metrics
Sections for Server info, Storage, Replication, and WiredTiger statistics
Safe connection management with proper cleanup on widget dispose
MongoDB Connection Management: Improved MongoDB connection handling
MongoService now disconnects existing connections before creating new ones (prevents stale connections)
MongoConnection.disconnect() safely handles already-closed connections
Comprehensive Tests: Added unit tests for MongoDB URI database replacement
Tests verify correct database path replacement in various URI formats
Tests ensure query parameters are preserved during database replacement
Tests cover edge cases (with/without auth, custom ports, connection strings)
Fixed
MongoDB URI Database Replacement Bug: Fixed critical bug where database path replacement in MongoDB URIs was incorrectly using regex replacement, causing $1 to be interpreted as a literal string instead of a regex capture group
Before: mongodb://root:root@127.0.0.1:27017 → mongodb://root:root@127.0.0.1:27017/admin$1 (incorrect)
After: mongodb://root:root@127.0.0.1:27017 → mongodb://root:root@127.0.0.1:27017/admin (correct)
Replaced regex-based URI manipulation with Uri.parse() and uri.replace() for reliable path replacement
Now correctly preserves query parameters (authSource, replicaSet, ssl) when replacing database paths
Fixed in listDatabases(), listCollections(), executeCommand(), find(), and aggregate() methods
Changed
Workspace Panel: Updated to display MongoStatsView instead of MongoDatabasesView when a MongoDB connection is selected, providing server statistics similar to Redis connections
Technical Details
Files Modified:
lib/core/database/mongodb_connection.dart: Replaced regex with Uri.parse() for database path replacement
lib/core/database/mongodb_service.dart: Updated all methods to use Uri.parse() for database replacement
lib/features/main_screen/workspace_panel.dart: Switched to MongoStatsView for MongoDB connections
Files Added:
lib/features/mongodb/mongo_stats_view.dart: New statistics view widget
test/core/database/mongodb_uri_replacement_test.dart: Comprehensive test suite
Testing
All 90 existing tests pass
Added 9 new tests for MongoDB URI replacement scenarios
Tests verify no literal $1 appears in final URIs (the bug we fixed)