Skip to main content
The Database component provides access to MongoDB for all persistent data storage. It uses a dual-database architecture with separate databases for authentication and game data.

Overview

Access the Database component via Database.Game (for game data) or Database.Auth (for authentication data).
Server-Side Only: Database operations are only available on the server. Never attempt database queries from client-side code.
Params Table Pattern: All MongoDB methods use a single params table as the first argument — NOT separate positional arguments. See examples below.

Call Signature

Every database method follows the same pattern:

Methods

findOne

Find a single document matching the query.
findOne internally calls find with limit = 1. The callback receives an array — access the first element with results[1].
With projection (return only specific fields):

find

Find multiple documents matching the query.
With limit:
With options (sort, projection):

insertOne

Insert a single document.
insertOne wraps the document into a single-element array and calls insert internally. The callback signature is (success, insertedCount, arrayOfIds).

insert

Insert multiple documents at once (bulk insert).
The method name is insert, NOT insertMany. The params.documents field must be an array of document tables.

updateOne

Update a single document matching the query.
Increment values:
Push to array:
Multiple operations at once:

update

Update all documents matching the query (bulk update).
The method name is update, NOT updateMany. Without the internal isUpdateOne flag, update applies to ALL matching documents.

deleteOne

Delete a single document matching the query.

delete

Delete all documents matching the query (bulk delete).
The method name is delete, NOT deleteMany. Without the internal isDeleteOne flag, delete removes ALL matching documents.

findOneAndUpdate

Atomically find a document, update it, and return the result.
This method is useful for atomic operations like generating sequential IDs.

count

Count documents matching the query.

aggregate

Run an aggregation pipeline.
The pipeline stages go in params.aggregate (NOT a separate pipeline argument).

Auth Database

The Auth database has the same methods as Game. Use it for accounts and bans:

Deprecated Methods

The top-level Database:method() calls (without .Game or .Auth) still work but print deprecation warnings. Always use Database.Game:method() or Database.Auth:method().

MySQL (oxmysql)

MySQL is available via the oxmysql resource for the inventory system and compatibility. It is NOT accessed through the Database component — use oxmysql exports directly:
See oxmysql documentation for full API reference.

Best Practices

Never use the top-level deprecated methods:
All methods take a single params table. The fields vary by method:
Create indexes for frequently queried fields:

Next Steps

Base API

Core framework exports

Logger API

Logging component

Database Architecture

Understanding the database system

Database Setup

Configure databases