CRUD Operations
CRUD Operations
Master Create, Read, Update, Delete operations with gmsv_mongo
CRUD Operations
CRUD (Create, Read, Update, Delete) operations are the foundation of database interactions. gmsv_mongo provides both synchronous and asynchronous versions of all operations.
Overview
Synchronous vs Asynchronous
| Type | Behavior | Use Case |
|---|---|---|
| Sync | Blocks until complete | Simple scripts, initialization |
| Async | Uses callbacks | Game logic, high-traffic operations |
Method Naming
- Synchronous:
InsertOne,Find,UpdateOne, etc. - Asynchronous:
InsertOneAsync,FindAsync,UpdateOneAsync, etc.
Quick Reference
Create Operations
| Method | Description |
|---|---|
InsertOne(doc) | Insert single document |
InsertMany(docs) | Insert multiple documents |
InsertOneAsync(doc, callback) | Async insert single |
InsertManyAsync(docs, callback) | Async insert multiple |
Read Operations
| Method | Description |
|---|---|
Find(filter [, limit]) | Find matching documents |
FindOne(filter) | Find first matching document |
Count(filter) | Count matching documents |
FindAsync(filter, limit, callback) | Async find |
FindOneAsync(filter, callback) | Async find one |
CountAsync(filter, callback) | Async count |
Update Operations
| Method | Description |
|---|---|
UpdateOne(filter, update [, upsert]) | Update first match |
UpdateMany(filter, update [, upsert]) | Update all matches |
UpdateOneAsync(filter, update, callback) | Async update one |
UpdateManyAsync(filter, update, callback) | Async update many |
Delete Operations
| Method | Description |
|---|---|
DeleteOne(filter) | Delete first match |
DeleteMany(filter) | Delete all matches |
DeleteOneAsync(filter, callback) | Async delete one |
DeleteManyAsync(filter, callback) | Async delete many |