Why Two Databases?
MongoDB (Primary)
Best for:
- Flexible schemas
- Nested data (inventory, character stats)
- Fast reads/writes
- JSON-like documents
- Scalability
MySQL (Secondary)
Best for:
- Structured data
- Complex queries
- Relationships/joins
- Compatibility with other resources
- SQL familiarity
Database Usage
MongoDB Databases
Mythic Framework uses two MongoDB databases:MySQL Database
MongoDB Usage
Accessing MongoDB
MongoDB operations are handled through the Node.js wrapper in mythic-base using asynchronous callback patterns. Location:mythic-base/core/sv_database.js
Database Architecture: Mythic uses two separate MongoDB databases accessed via the
Database component:Database.Gameβ Game data (characters, inventory, vehicles, etc.)Database.Authβ Authentication data (users, roles, bans)
RetrieveComponents(), use Database.Game:method() directly. The full path is Database.Game but the local shorthand is standard.MongoDB Methods
findOne(params, callback)
findOne(params, callback)
Find a single document matching query.Callback receives:
(success, document)find(params, callback)
find(params, callback)
Find multiple documents.Callback receives:
(success, documents)insertOne(params, callback)
insertOne(params, callback)
Insert a single document.Callback receives:
(success, insertedDocument)updateOne(params, callback)
updateOne(params, callback)
Update a single document.Callback receives:
(success, updateResult)deleteOne(params, callback)
deleteOne(params, callback)
Delete a single document.Callback receives:
(success, deleteResult)count(params, callback)
count(params, callback)
Count documents matching query.Callback receives:
(success, count)aggregate(params, callback)
aggregate(params, callback)
Advanced aggregation queries.Callback receives:
(success, results)MongoDB Query Operators
MySQL Usage
Accessing MySQL
MySQL operations use oxmysql resource:Common MySQL Queries
SELECT Queries
SELECT Queries
INSERT Queries
INSERT Queries
UPDATE Queries
UPDATE Queries
DELETE Queries
DELETE Queries
Data Models
Character Document (MongoDB)
Inventory Document (MongoDB)
Vehicle Record (MySQL)
Best Practices
1. Use MongoDB for Game Data
1. Use MongoDB for Game Data
Store dynamic, frequently-changing data in MongoDB:
2. Use MySQL for Relational Data
2. Use MySQL for Relational Data
Use MySQL when you need complex relationships:
3. Index Your Collections
3. Index Your Collections
Add indexes for frequently queried fields:
4. Sanitize User Input
4. Sanitize User Input
Always use parameterized queries:
5. Handle Errors
5. Handle Errors
Database operations can fail. Always handle errors in callbacks:
6. Batch Operations
6. Batch Operations
When possible, batch database operations:
7. Cache When Appropriate
7. Cache When Appropriate
Cache frequently accessed, rarely changing data:
Performance Optimization
MongoDB Optimization
MySQL Optimization
Database Migration
When updating schemas:Next Steps
Database Setup
Initial database configuration
Database API
Database API reference
Architecture
Framework architecture overview
Configuration
Database connection settings