const classafMongo::Database

sys::Obj
  afMongo::Database

Represents a MongoDB database.

authenticate

Source

Obj? authenticate(Str userName, Str password, |Database->Obj? func)

Executes the given function passing in a database (connection) that has been authenticated with the given user. Within the function, the authenticated database may be used as often as you wish.

data := db.authenticate("ZeroCool", "password") |authDb -> Obj?| {

    return authDb["top-secret"].findAll
}

All Mongo objects ( Collection, Index, User, etc...) created from the authenticated database will inherit the user credentials.

collection

Source

Collection collection(Str collectionName)

Returns a Collection with the given name.

Note this just instantiates the Fantom object, it does not create anything in the database.

collectionNames

Source

Str[] collectionNames()

Returns true if this collection exists.

drop

Source

This drop()

dropAllUsers

Source

Int dropAllUsers()

Drops ALL users from this database. Be careful!

Returns the number of users dropped.

@see http://docs.mongodb.org/manual/reference/command/dropAllUsersFromDatabase/

eval

Source

Obj? eval(Code func, Obj?[] args := [,], Bool noLock := false)

Evaluates a JavaScript function on the database server.

scope := ["y":2]
func  := Code("function (x) { return x + y; }", scope)
xy    := db.eval(func, [3f])  // --> 5.0

@see http://docs.mongodb.org/manual/reference/command/eval/

get

Source

@Operator
Collection get(Str collectionName)

Convenience / shorthand notation for collection(name)

makeWithName

Source

new makeWithName(ConnectionManager connectionManager, Str name, |This? f := null)

Creates a Database with the given name.

Note this just instantiates the Fantom object, it does not create anything in the database.

name

Source

const Str name

The name of the database.

runCmd

Source

Str:Obj? runCmd(Str:Obj? cmd)

For Power Users!

Runs any arbitrary command against this database.

Note you must set the write concern yourself, should the command take one.

stats

Source

Str:Obj? stats(Int scale := 1)

Returns storage statistics for this database.

@see http://docs.mongodb.org/manual/reference/command/dbStats/

user

Source

User user(Str userName)

Returns a User with the given name.

Note this just instantiates the Fantom object, it does not create anything in the database.

userNames

Source

Str[] userNames()

Returns all the index names of this collection.