stock-bot/libs/mongodb-client
2025-06-20 08:42:58 -04:00
..
src fixed more lint issues 2025-06-20 08:42:58 -04:00
package.json removed configs from all libs and will inject them within the services themselves 2025-06-18 14:50:47 -04:00
README.md linxus fs fixes 2025-06-09 22:55:51 -04:00
tsconfig.json updated config files and starting work on utils lib 2025-06-19 09:35:03 -04:00

MongoDB Client Library

A comprehensive MongoDB client library for the Stock Bot trading platform, designed for handling document storage, raw data, and unstructured content.

Features

  • Connection Management: Robust connection pooling and failover
  • Schema Validation: Built-in validation using Zod schemas
  • Type Safety: Full TypeScript support with typed collections
  • Error Handling: Comprehensive error handling and retry logic
  • Health Monitoring: Connection health monitoring and metrics
  • Transactions: Support for multi-document transactions
  • Aggregation: Helper methods for complex aggregation pipelines

Usage

import { MongoDBClient } from '@stock-bot/mongodb-client';

// Initialize client
const mongoClient = new MongoDBClient();
await mongoClient.connect();

// Get a typed collection
const collection = mongoClient.getCollection('sentiment_data');

// Insert document
await collection.insertOne({
  symbol: 'AAPL',
  sentiment: 'positive',
  source: 'reddit',
  timestamp: new Date()
});

// Query with aggregation
const results = await collection.aggregate([
  { $match: { symbol: 'AAPL' } },
  { $group: { _id: '$sentiment', count: { $sum: 1 } } }
]);

Collections

The client provides typed access to the following collections:

  • sentiment_data: Social media sentiment analysis
  • raw_documents: Unprocessed documents and content
  • news_articles: Financial news and articles
  • sec_filings: SEC filing documents
  • earnings_transcripts: Earnings call transcripts
  • analyst_reports: Research reports and analysis

Configuration

Configure using environment variables:

MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_DATABASE=trading_documents
MONGODB_USERNAME=trading_admin
MONGODB_PASSWORD=your_password

Health Monitoring

The client includes built-in health monitoring:

const health = await mongoClient.getHealth();
console.log(health.status); // 'healthy' | 'degraded' | 'unhealthy'