Connection
Connection
Manage MongoDB connections with gmsv_mongo
Connection Management
This section covers all aspects of connecting to MongoDB with gmsv_mongo.
Overview
gmsv_mongo provides two methods for creating connections:
MongoDB.Client()- Simple connection with default settingsMongoDB.ClientWithOptions()- Advanced connection with custom options
Connection Lifecycle
-- 1. Create connection
local client = MongoDB.Client("mongodb://localhost:27017")
-- 2. Use connection for operations
local db = client:Database("mydb")
local collection = db:Collection("mycollection")
-- 3. Connection is managed automatically
-- No explicit close/disconnect needed
Quick Reference
| Method | Description | Returns |
|---|---|---|
MongoDB.Client(uri) | Create basic connection | MongoDBClient or nil |
MongoDB.ClientWithOptions(uri, options) | Create connection with options | MongoDBClient or nil |
client:Database(name) | Get database reference | MongoDBDatabase |
client:ListDatabases() | List all databases | table of strings |