Getting Started
Configuration
Configure gmsv_mongo connection options and settings
Configuration
This guide covers all configuration options available when connecting to MongoDB.
Connection String Format
MongoDB connection strings follow this format:
mongodb://[username:password@]host[:port][/database][?options]
Examples
-- Local connection (no auth)
MongoDB.Client("mongodb://localhost:27017")
-- With authentication
MongoDB.Client("mongodb://admin:password@localhost:27017")
-- Remote server
MongoDB.Client("mongodb://user:pass@192.168.1.100:27017")
-- MongoDB Atlas (SRV)
MongoDB.Client("mongodb+srv://user:pass@cluster.mongodb.net")
-- With database and options
MongoDB.Client("mongodb://user:pass@host:27017/mydb?authSource=admin")
Connection Options
Use ClientWithOptions for advanced configuration:
local client = MongoDB.ClientWithOptions("mongodb://localhost:27017", {
app_name = "MyGModServer",
max_pool_size = 50,
retry_writes = true
})
Available Options
| Option | Type | Default | Description |
|---|---|---|---|
app_name | string | "gmsv_mongo_v2" | Application name for server logs |
max_pool_size | number | 100 | Maximum connections in pool |
retry_writes | boolean | true | Retry failed write operations |
Default Configuration Values
The library uses these defaults (from the Rust config):
-- Default connection pool settings
max_pool_size = 100
min_pool_size = 10
-- Default timeouts
server_selection_timeout = 30 -- seconds
connect_timeout = 10 -- seconds
max_idle_time = 600 -- seconds (10 minutes)
-- Default retry behavior
retry_writes = true
retry_reads = true
Connection Pooling
gmsv_mongo automatically manages a connection pool for optimal performance:
-- Configure pool size based on your server's needs
local client = MongoDB.ClientWithOptions("mongodb://localhost:27017", {
max_pool_size = 50, -- For high-traffic servers
})
-- Connections are automatically:
-- - Reused across operations
-- - Managed for health and timeouts
-- - Cleaned up when idle
Pool Size Guidelines
| Server Type | Recommended Pool Size |
|---|---|
| Development | 10-20 |
| Small server (<32 players) | 20-50 |
| Medium server (32-64 players) | 50-100 |
| Large server (64+ players) | 100+ |
Environment-Specific Configuration
Development
local client = MongoDB.ClientWithOptions("mongodb://localhost:27017", {
app_name = "GModDev",
max_pool_size = 10
})
Production
local client = MongoDB.ClientWithOptions("mongodb://user:pass@prod-server:27017", {
app_name = "GModProd",
max_pool_size = 100,
retry_writes = true
})
Docker/Containerized
-- Use service name when MongoDB is in same Docker network
local client = MongoDB.Client("mongodb://mongo:27017")
-- Or with authentication
local client = MongoDB.Client("mongodb://root:example@mongo:27017")
Utility Functions
Version Check
print("MongoDB Module Version:", MongoDB.Version())
Suppress Messages
Control console output from the module:
-- Suppress informational messages
MongoDB.SuppressMessages(true)
-- Re-enable messages
MongoDB.SuppressMessages(false)
Best Practices
- Use connection strings from environment: Don't hardcode credentials
- Configure appropriate pool sizes: Match your server's traffic patterns
- Enable retry writes: Handles transient network issues
- Use app_name: Helps identify connections in MongoDB logs
- Test connections: Verify connectivity before operations
Next Steps
- First Steps - Start using gmsv_mongo
- Connection Management - Deep dive into connections