const classafMongo::MongoClient

sys::Obj
  afMongo::MongoClient

A MongoDB client.

This class is the main starting point for connecting to a MongoDB instance.

Retrieving data from a MongoDB can be as easy as:

mongo := MongoClient(`mongodb://localhost:27017/`)
data  := mongo.db("db").collection("col").find

Or using defaults and shorthand notation:

data  := mongo["db"]["col"].find
adminCmd

Source

MongoCmd adminCmd(Str cmdName, Obj? cmdVal := 1)

For Power Users!

Runs an arbitrary command against the admin database.

Don't forget to call run()!

buildInfo

Source

Str:Obj? buildInfo()

Returns a build information of the connected MongoDB server. Use to obtain the version of the MongoDB server.

@see https://www.mongodb.com/docs/manual/reference/command/buildInfo/

connMgr

Source

const MongoConnMgr connMgr

The connection manager that Mongo connections are leased from.

db

Source

MongoDb db(Str? dbName := null)

Returns a Database with the given name.

If dbName is null, the default database from MongoConnMgr is used.

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

get

Source

@Operator
MongoDb get(Str dbName)

Convenience / shorthand notation for db(name)

hello

Source

Str:Obj? hello()

Sends a hello command - if hello is not available, a legacy isMaster command is sent instead.

listDatabaseNames

Source

Str[] listDatabaseNames()

Returns all the database names on the MongoDB instance.

This is more optimised than just calling listDatabases().

listDatabases

Source

Str:Obj?[] listDatabases([Str:Obj?]? filter := null)

Returns a list of existing databases, along with some basic info.

@see https://www.mongodb.com/docs/manual/reference/command/listDatabases/

make

Source

new make(MongoConnMgr connMgr)

Creates a MongoClient with the given ConnectionManager.

makeFromUri

Source

new makeFromUri(Uri mongoUrl)

Creates a MongoClient with a pooled connection to the given Mongo connection URL.

ping

Source

Str:Obj? ping()

Sends a ping command to the server. pings should return straight away, even if the server is write-locked.

@see https://www.mongodb.com/docs/manual/reference/command/ping/

shutdown

Source

Void shutdown()

Convenience for MongoConnMgr.shutdown().