stock-bot/libs/data/mongodb
2025-07-04 17:04:47 -04:00
..
src socket reruns 2025-07-04 17:04:47 -04:00
test fixed build libs 2025-06-25 08:29:53 -04:00
package.json moved folders around 2025-06-21 18:27:00 -04:00
README.md moved folders around 2025-06-21 18:27:00 -04:00
tsconfig.json format 2025-06-22 17:55:51 -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';

// 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'