feat: add mongodb connector#128
Conversation
|
@Taukon look good, make sure you run npm run integration, and that those tests pass. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds MongoDB and GridFS support as alternatives to AWS services (DynamoDB and S3), implementing a service abstraction layer to switch between storage backends.
- Introduces MongoDB connection handling and data storage classes (MongoDataSender, GridFSManager)
- Creates a service factory pattern that initializes either AWS or MongoDB services based on configuration
- Refactors the application initialization to use the new service abstraction layer
Reviewed Changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/store/MongoDataSender.js | Implements MongoDB data storage using Mongoose with schema definition and error handling |
| src/store/GridFSManager.js | Provides GridFS file storage functionality with gzip compression |
| src/services/index.js | Service factory that initializes either AWS or MongoDB services based on configuration |
| src/services/MongoDB.js | MongoDB service setup functions for connection and service initialization |
| src/services/AWS.js | Extracted AWS service setup functions from main application |
| src/app.js | Refactored to use service factory instead of direct service initialization |
| src/RTCStatsServer.js | Moved server setup functions to separate module and updated service injection |
| src/ServerSetup.js | Extracted HTTP/HTTPS server setup logic from RTCStatsServer |
| config files | Added MongoDB configuration options and service type selection |
| package.json | Added mongodb and mongoose dependencies |
| test files | Comprehensive test coverage for new MongoDB components with mocking |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/store/MongoDataSender.js
Outdated
| */ | ||
| constructor(collectionName) { | ||
|
|
||
| assert(collectionName, 'Collection Name is required when initializing MongoDB'); |
There was a problem hiding this comment.
The error message is inconsistent with the constructor parameter name. It should say 'Collection Name is required' to match the parameter name 'collectionName'.
| assert(collectionName, 'Collection Name is required when initializing MongoDB'); | |
| assert(collectionName, "'collectionName' is required when initializing MongoDB"); |
src/store/MongoDataSender.js
Outdated
| versionKey: false | ||
| }); | ||
|
|
||
| this._model = mongoose.models.Metadata || mongoose.model('Metadata', metadataSchema); |
There was a problem hiding this comment.
The hardcoded model name 'Metadata' should be configurable or derived from the collection name to avoid conflicts when multiple instances use different collections.
| this._model = mongoose.models.Metadata || mongoose.model('Metadata', metadataSchema); | |
| // Derive a unique model name from the collection name to avoid conflicts | |
| const modelName = `Metadata_${collectionName.replace(/[^a-zA-Z0-9]/g, '_')}`; | |
| this._model = mongoose.models[modelName] || mongoose.model(modelName, metadataSchema); |
|
@andrei-gavrilescu I pushed the fixes for Copilot's suggestions. Both |
This PR adds support for MongoDB and GridFS as alternatives to the existing AWS services (DynamoDB and S3).