Introduction

Introduction

Welcome to gmsv_mongo - A comprehensive MongoDB driver for Garry's Mod

Introduction to gmsv_mongo

gmsv_mongo is a high-performance MongoDB driver for Garry's Mod, enabling you to leverage the power of MongoDB for your game server data storage and management. Built with Rust for maximum performance and safety, it provides a comprehensive Lua API for all your database needs.

What is gmsv_mongo?

gmsv_mongo bridges the gap between Garry's Mod servers and MongoDB databases, allowing you to:

  • Store player data persistently across server restarts
  • Build complex systems like inventories, economies, and leaderboards
  • Query and aggregate data with MongoDB's powerful query language
  • Scale your server data without worrying about file-based limitations
  • Leverage modern database features like indexes for blazing-fast queries

Why MongoDB for Garry's Mod?

High Performance

Built with Rust and async I/O for optimal performance, with connection pooling and efficient BSON serialization.

Flexible Schema

MongoDB's document-based structure perfectly matches Lua's table-based data model.

Scalable

Handle millions of documents with ease. MongoDB scales with your server's needs.

Powerful Queries

Advanced querying with operators, aggregation pipelines, and full-text search support.

Data Safety

ACID transactions, automatic backups, and built-in replication for data durability.

Easy to Use

Clean, intuitive Lua API that feels natural for GMod developers.

Key Features

gmsv_mongo comes packed with features designed for modern game server development:

  • Connection Pooling: Efficient connection management with configurable pool sizes
  • Complete CRUD Operations: Insert, Find, Update, Delete with single and bulk variants
  • Aggregation Pipelines: Complex data analysis and transformations
  • Index Management: Create, list, and drop indexes for query optimization
  • Advanced Queries: Support for all MongoDB query operators ($gt, $in, $regex, etc.)
  • Type Safety: Automatic Lua ↔ BSON type conversion with proper error handling
  • Cross-Platform: Works on Windows and Linux, both 32-bit and 64-bit

Who Should Use gmsv_mongo?

gmsv_mongo is perfect for:

  • Server Owners who need reliable, scalable data storage
  • Developers building complex game modes with persistent data
  • Communities running multiple servers that need shared data
  • Admins who want modern database tools for their servers

Quick Example

Here's a taste of what you can do with gmsv_mongo:

require("mongo")

-- Connect to MongoDB
local client = MongoDB.Client("mongodb://localhost:27017")
local db = client:Database("gameserver")
local players = db:Collection("players")

-- Save player data
local id = players:InsertOne({
    steamid = "STEAM_0:1:12345",
    username = "Player1",
    level = 5,
    credits = 1000,
    inventory = {
        { item = "weapon_pistol", amount = 1 },
        { item = "ammo_pistol", amount = 50 }
    }
})

-- Find high-level players
local veterans = players:Find({ 
    level = { ["$gte"] = 10 } 
}, 10)

-- Update player credits
players:UpdateOne(
    { steamid = "STEAM_0:1:12345" },
    { ["$inc"] = { credits = 500 } }
)

-- Get statistics with aggregation
local stats = players:Aggregate({
    {
        ["$group"] = {
            _id = nil,
            avgLevel = { ["$avg"] = "$level" },
            totalPlayers = { ["$sum"] = 1 }
        }
    }
})

Next Steps

Ready to get started? Follow our installation guide:

Install gmsv_mongo

Or explore the documentation: