https://github.com/dhkatz/gmsv_mongodb
A MongoDB module for Garry's Mod
https://github.com/dhkatz/gmsv_mongodb
garrysmod gmod gmod-modules mongodb
Last synced: about 2 months ago
JSON representation
A MongoDB module for Garry's Mod
- Host: GitHub
- URL: https://github.com/dhkatz/gmsv_mongodb
- Owner: dhkatz
- License: mit
- Created: 2020-03-14T06:55:46.000Z (about 6 years ago)
- Default Branch: development
- Last Pushed: 2020-06-19T11:58:46.000Z (almost 6 years ago)
- Last Synced: 2023-03-10T01:31:58.111Z (about 3 years ago)
- Topics: garrysmod, gmod, gmod-modules, mongodb
- Language: C++
- Homepage:
- Size: 93.8 KB
- Stars: 18
- Watchers: 1
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gmsv_mongodb
A MongoDB module for Garry's Mod!
| Windows | Linux |
|---------|-------|
| [](https://ci.appveyor.com/project/dhkatz/gmsv-mongodb/branch/development)| [](https://travis-ci.com/dhkatz/gmsv_mongodb) |
## Quickstart
### Information
Why does Garry's Mod need a MongoDB module? Because MongoDB is a NoSQL database.
MySQL is designed for static schemas and performs best with complex queries.
Typically, the data stored by Garry's Mod servers is extremely dynamic
and the queries performed are very simple. This makes MySQL a pain.
With MongoDB you don't have to worry about schemas at all! Just write
and query whatever data you want!
### Download
Download a pre-built binary for your system from the [Releases](https://github.com/dhkatz/gmsv_mongodb/releases) section.
Place the `.dll` in `garrysmod/lua/bin`.
## Usage
For more details see the [documentation](docs/README.md) or [examples](examples).
```lua
require('mongodb')
-- Note: Connecting to the MongoDB cluster can hang! Cache the result in a global!
client = client or mongodb.Client('', '')
-- Retrieve databases
local database = client:Database('test')
-- Retrieve collections
local players = database:GetCollection('players')
-- Run queries (Find, Insert, Update, Remove)
local data = players:Find({ name = 'Bob', age = 25 })
print(data[1].name)
players:Update({ name = 'Bob' }, { ['$set'] = { age = 26 } })
-- Execute bulk queries
local bulk = players:Bulk()
for i, ply in ipairs({ 'Bob', 'Jim', 'Ann' }) do
bulk:Insert({ name = ply, age = 20 + i })
end
local result = bulk:Execute()
```
## License
Code licensed under the [MIT License](LICENSE).