Overview
Access the Database component viaDatabase.Game (for game data) or Database.Auth (for authentication data).
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].find
Find multiple documents matching the query.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).updateOne
Update a single document matching the query.update
Update all documents matching the query (bulk update).deleteOne
Delete a single document matching the query.delete
Delete all documents matching the query (bulk delete).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.Auth Database
The Auth database has the same methods as Game. Use it for accounts and bans:Deprecated Methods
The top-levelDatabase: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 theoxmysql resource for the inventory system and compatibility. It is NOT accessed through the Database component — use oxmysql exports directly:
Best Practices
Always Use Database.Game or Database.Auth
Always Use Database.Game or Database.Auth
Never use the top-level deprecated methods:
Handle Errors in Callbacks
Handle Errors in Callbacks
Use Params Table Correctly
Use Params Table Correctly
All methods take a single params table. The fields vary by method:
Index Your Collections
Index Your Collections
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