Skip to content

SkinnyPeteTheGiraffe/n-mongodb

Repository files navigation

N-MongoDB (FiveM)

MongoDB wrapper for use within FiveM

A typescript implementation of a MongoDB wrapper for use within FiveM. Completely written in typescript, exporting functions to easily access and manipulate a Mongo database. Adapted from @alcoholiclobster's fivem-mongodb, but rewritten in Typescript to be modular, and type safe.

Installation

  • Clone the library, update NPM, and build:
    git clone https://github.com/SkinnyPeteTheGiraffe/n-mongodb.git mongodb
    cd mongodb
    yarn install
    yarn run build
    
  • Create a database.cfg and place it within your server root directory.
    • Add the following lines to the database.cfg file (do not include <>):
        set mongodb_host <REPLACE_WITH_MONGO_HOST>
        set mongodb_collection <REPLACE_WITH_MONGO_COLLECTION_NAME>
  • At the top of your server.cfg include (before ensure):
    exec "database.cfg"
  • Include the library in your server.cfg:
    ensure mongodb

Usage Examples

Original Example (Lua):
exports.mongodb:findOne({ collection = "users", query = { _id = id } }, function (success, result)
    if not success then
        print("Error message: "..tostring(result))
        return
    end
    print("User name is "..tostring(result[1].name))
end)
Example (JS/TS)
exports.mongodb.findOne({ collection: "users", query: { _id: id } }, (success, result) => {
    if (!success) {
        console.log(`Error message: ${result}`)
        return
    }
    console.log(`User name is ${result[1].name}`)
})

About

MongoDB wrapper for use within FiveM

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published