This resource is a simple MongoDB wrapper for FiveM. It's running on top of MongoDB Node Driver.
- Clone this repository to
resources/mongodbfolder. - Copy
mongodb/database.cfgto your server root directory. - Add the following lines to your server config:
exec "database.cfg"
start mongodb
- Change
mongodb_urlandmongodb_databaseindatabase.cfg. - Run
npm installinresources/mongodbdirectory.
Every callback accepts success<boolean> as its first argument. If success is false, second argument contains error message.
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)- Returns boolean
Returns true if database connection is established.
params<Object>- params objectparams.collection<string>- collection nameparams.documents<Object>- an array of documents to insertparams.options<Object>- optional settings object. See collection.insertMany in docscallback(success<boolean>, insertedCount<number>, insertedIds<Array>)- callback (optional) Inserts an array of documents into MongoDB.
params<Object>- params objectparams.collection<string>- collection nameparams.document<Object>- document objectparams.options<Object>- optional settings object. See collection.insertMany in docscallback(success<boolean>, insertedCount<number>, insertedIds<Array>)- callback (optional)
Inserts a single document into MongoDB.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.options<Object>- optional settings object. See collection.find in docsparams.limit<number>- limit documents countcallback(success<boolean>, documents<Array>)- callback (optional)
Performs a find query.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.options<Object>- optional settings object. See collection.find in docscallback(success<boolean>, documents<Array>)- callback (optional)
Performns a find query with limit = 1.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.update<Object>- update query objectparams.options<Object>- optional settings object. See collection.updateMany in docscallback(success<boolean>, updatedCount<number>)- callback (optional)
Update multiple documents on MongoDB.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.update<Object>- update query objectparams.options<Object>- optional settings object. See collection.updateMany in docscallback(success<boolean>, updatedCount<number>)- callback (optional)
Update a single document on MongoDB.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.options<Object>- optional settings object. See collection.countDocuments in docscallback(success<boolean>, count<number>)- callback (optional)
Gets the number of documents matching the filter.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.options<Object>- optional settings object. See collection.deleteMany in docscallback(success<boolean>, deletedCount<number>)- callback (optional)
Delete multiple documents on MongoDB.
params<Object>- params objectparams.collection<string>- collection nameparams.query<Object>- filter query objectparams.options<Object>- optional settings object. See collection.deleteMany in docscallback(success<boolean>, deletedCount<number>)- callback (optional)
Delete a document on MongoDB.