Skip to content

Mongodb stats - #8

Merged
Reei-dp merged 4 commits into
devfrom
mongodb-stats
Mar 5, 2026
Merged

Mongodb stats#8
Reei-dp merged 4 commits into
devfrom
mongodb-stats

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

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)

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)
@ZhuchkaTriplesix
ZhuchkaTriplesix requested a review from Reei-dp March 5, 2026 21:10
@ZhuchkaTriplesix ZhuchkaTriplesix self-assigned this Mar 5, 2026
@ZhuchkaTriplesix ZhuchkaTriplesix added bug Something isn't working enhancement New feature or request labels Mar 5, 2026

@ZhuchkaTriplesix ZhuchkaTriplesix left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

15/10

@Reei-dp Reei-dp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gj

@Reei-dp
Reei-dp merged commit 8676f3b into dev Mar 5, 2026
2 checks passed
@Reei-dp
Reei-dp deleted the mongodb-stats branch March 5, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants