const classafMongo::Database
sys::Obj afMongo::Database
Represents a MongoDB database.
- authenticate
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
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
Str[] collectionNames()
Returns
true
if this collection exists.- drop
This drop()
Drops the database. Be careful!
@see http://docs.mongodb.org/manual/reference/command/dropDatabase/
- dropAllUsers
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
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- get
@
Operator
Collection get(Str collectionName)Convenience / shorthand notation for
collection(name)
- makeWithName
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
const Str name
The name of the database.
- runCmd
For Power Users!
Runs any arbitrary command against this database.
Note you must set the write concern yourself, should the command take one.
- stats
Str:Obj? stats(Int scale := 1)
Returns storage statistics for this database.
@see http://docs.mongodb.org/manual/reference/command/dbStats/
- user
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
Str[] userNames()
Returns all the index names of this collection.