Skip to content
develephant edited this page Feb 4, 2016 · 2 revisions

You will need a Mongo database connection object for these methods. See Connection.

Methods:

Collections

:list

List the collections for the currently selected database.

Parameters

None

Returns

A table array of collections, or nil.

local collections = db:list()
for _, collection in ipairs( collections ) do
  print( collection.name )
end

:get_col

Get a collection reference from the database.

Parameters

Name Description Default Required
collection_name A string name of the collection none Yes

Returns

A collection object, or nil.

local collection = db:get_col( collection_name )

Authentication

:add_user

Adds a database User for authentication.

Parameters

Name Description Default Required
username A string name for the database User none Yes
password A string password for the database User none Yes

Returns

On success returns 1, or nil and error message.

local ok, err = db:add_user( username, password )

:auth

Authenticates a User with the database.

Parameters

Name Description Default Required
username A string name for the database User none Yes
password A string password for the database User none Yes

Returns

On success returns 1, or nil and error message.

local ok, err = db:auth( username, password )

GridFS

:get_gridfs

Usage unknown.

Parameters

Name Description Default Required
fs Usage unknown ? ?

Returns

A gridfs object.

local gridfs = db:get_gridfs( fs )

Maintenance

:dropDatabase

Removes the selected database, and all related collections.

Parameters

None

Returns

Nothing

db:dropDatabase()
Clone this wiki locally