Skip to content
On this page

Collection (extends: object)

An Object which represents a Collection within the Database.

INFO

Some Methods might return an errorMessage instead of a message if an unexpected error occurs. An errorMessage is only returned if the error is unexpected and not caused by the developer and also only set by the Client itself, not by the Server.

If an unexpected error occurs, it will return an errorMessage.

lua
{
    ["success"] = false,
    ["errorMessage"] = "An unexpected error occured."
}

If an error occurs which is caused by the developer (probl.), it will return a message.

lua
{
    ["success"] = false,
    ["message"] = "{Some error returned by the Server}"
}

:drop()

DANGER

This will delete the Collection and all Documents within it. This action can not be undone. Use with caution.

Will Drop the Collection from the Database.

lua
--///

local Response = Collection:drop()

/*
{
    ["success"] = true
}
*/

:insert(documentData: data)

Will Insert a Document into the Collection and will return it as an Entry Object.

lua
--///

local Entry = Collection:insert({
    ["name"] = "JavaScript",
    ["type"] = "Programming Language",
    ["creator"] = "Brendan Eich",
    ["year"] = 1995,
    ["description"] = "JavaScript is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm.",
    ["links"] = {
        ["Wikipedia"] = "https://en.wikipedia.org/wiki/JavaScript",
        ["MDN"] = "https://developer.mozilla.org/en-US/docs/Web/JavaScript"
    }
})

/*
[Entry]
*/

:delete(documentData: filters)

DANGER

This will delete all Documents which match the given filters. This action can not be undone. Use with caution.

Will Delete all Documents which match the given filters and will return the amount of Documents as deletedEntries which were deleted.

lua
--///

local Response = Collection:delete({
    ["name"] = "JavaScript"
})

/*
{
    ["success"] = true,
    ["deletedEntries"] = 1
}
*/

:select(documentData: filters)

Will Select all Documents which match the given filters and will return them as an Array of Entry Objects.

lua
--///

local Entries = Collection:select({
    ["name"] = "JavaScript"
})

/*
{
    ["success"] = true,
    ["entries"] = {
        [1] = [Entry],
        [2] = [Entry],
        [3] = [Entry],
        ...
    }
}
*/

:update(documentData: filters, documentData: data)

Will Update all Documents which match the given filters and will return the amount of Documents as modifiedEntries which were updated.

DANGER

This will update all Documents which match the given filters. This action can not be undone. Use with caution.

lua
--///

local Response = Collection:update({
    ["name"] = "JavaScript"
}, {
    ["likes"] = -500
})

/*
{
    ["success"] = true,
    ["modifiedEntries"] = 1
}
*/