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
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
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
const MongoConnMgr connMgr
The connection manager that Mongo connections are leased from.
- db
MongoDb db(Str? dbName := null)
Returns a
Database
with the given name.If
dbName
isnull
, the default database fromMongoConnMgr
is used.Note this just instantiates the Fantom object, it does not create anything in the database.
- get
@
Operator
MongoDb get(Str dbName)Convenience / shorthand notation for
db(name)
- hello
Sends a
hello
command - ifhello
is not available, a legacyisMaster
command is sent instead.- listDatabaseNames
Str[] listDatabaseNames()
Returns all the database names on the MongoDB instance.
This is more optimised than just calling
listDatabases()
.- listDatabases
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
new make(MongoConnMgr connMgr)
Creates a
MongoClient
with the givenConnectionManager
.- makeFromUri
new makeFromUri(Uri mongoUrl)
Creates a
MongoClient
with a pooled connection to the given Mongo connection URL.- 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
Void shutdown()
Convenience for
MongoConnMgr.shutdown()
.