const classafMongo::MongoConnUrl
sys::Obj afMongo::MongoConnUrl
Parses a Mongo Connection URL into known options.
If user credentials are supplied, they are used as default authentication for each connection.
The following URL options are supported:
ssl
tls
connectTimeoutMS
socketTimeoutMS
compressors
zlibCompressionLevel
minPoolSize
maxPoolSize
waitQueueTimeoutMS
maxIdleTimeMS
w
wtimeoutMS
journal
authSource
authMechanism
authMechanismProperties
appName
retryWrites
retryReads
disableTxns
(unofficial)
URL examples:
mongodb://username:password@example1.com/database?maxPoolSize=50
mongodb://example2.com?minPoolSize=10&maxPoolSize=50&ssl=true
See https://www.mongodb.com/docs/manual/reference/connection-string/.
- appName
const Str? appName
The application name this client identifies itself to the MongoDB server as. Used by MongoDB when logging.
mongodb://example.com/puppies?appName=WattsApp
- authMechs
const Str:MongoAuthMech authMechs := ...
The auth mechanisms used for authenticating connections.
- compressors
const Str[] compressors
A list of compressors, as understood by this driver and presented to the MongoDB server. Any options supplied to the MongoURL and not understood by this driver will not be present in this list.
mongodb://example.com/puppies?compressors=snappy,zlib
Mongo understands
snappy,
zlib',zstd
, but currently this driver ONLY understandszlib
.This option may be used to disable wire compression, by suppling an empty list.
mongodb://example.com/puppies?compressors=
If not defined, this defaults to
["zlib"]
.- connectTimeout
const Duration? connectTimeout
The amount of time to attempt a socket connection before timing out. If
null
(the default) then a system timeout is used.mongodb://example.com/puppies?connectTimeoutMS=25000
Equates to inet::SocketOptions.connectTimeout.
- connectionUrl
const Uri connectionUrl
The original URL this class was initialised with. May contain authentication details.
mongodb://username:password@example1.com/puppies?maxPoolSize=50
- dbName
const Str? dbName
The default database name - taken from the path.
mongodb://example1.com/<database>
- disableTxns
const Bool disableTxns
An "unofficial" option that can be useful for development.
Transactions CANNOT be run against standalone MongoDB servers (MongoDB raises errors).
This option switches transactions off, and instead executes the txnFn outside of a transaction. This means the same app code may be used in both standalone and clustered environments.
mongodb://example.com/puppies?disableTxns=true
This option exists because MongoDB does NOT provide a sure-fire way of identifying standalone instances. Plus, automatically disabling txns could be dangerous and give the user a false sense of security.
- fromUrl
new fromUrl(Uri connectionUrl)
Parses a Mongo Connection URL.
- maxIdleTime
const Duration maxIdleTime := 10sec
The maximum time a connection can remain idle in the pool before being removed and closed. (This does NOT override minPoolSize.)
This helps ease connection throttling during bursts of activity.
Defaults to 10sec.
mongodb://example.com/puppies?maxIdleTimeMS=15000
- maxPoolSize
const Int maxPoolSize := 10
The maximum number of database connections the pool is allowed to open. This is the maximum number of concurrent users you expect your application to have.
Defaults to 10.
mongodb://example.com/puppies?maxPoolSize=10
- minPoolSize
const Int minPoolSize := 1
The minimum number of database connections the pool should keep open.
Defaults to 1.
mongodb://example.com/puppies?minPoolSize=50
- mongoCreds
const MongoCreds? mongoCreds
The credentials (if any) used to authenticate connections against MongoDB.
- retryReads
const Bool retryReads
An option to turn off retryable reads. (Defaults to
true
).mongodb://example.com/puppies?retryReads=false
- retryWrites
const Bool retryWrites
An option to turn off retryable writes. (Defaults to
true
).mongodb://example.com/puppies?retryWrites=false
- socketTimeout
const Duration? socketTimeout
The amount of time to attempt a send or receive on a socket before timing out.
null
(the default) indicates an infinite timeout.mongodb://example.com/puppies?socketTimeoutMS=25000
Equates to inet::SocketOptions.receiveTimeout.
- tls
const Bool tls := false
Specifies a TLS / SSL connection. Set to
true
for Mongo Atlas databases.Defaults to
false
.mongodb://example.com/puppies?tls=true mongodb://example.com/puppies?ssl=true
- waitQueueTimeout
const Duration waitQueueTimeout := 12sec
The maximum time a thread can wait for a connection to become available.
Defaults to 12 seconds.
mongodb://example.com/puppies?waitQueueTimeoutMS=12000
- writeConcern
const [Str:Obj?]? writeConcern
The default write concern for all write operations. Set by specifying the
w
,wtimeoutMS
andjournal
connection string options.mongodb://username:password@example1.com/puppies?w=1&wtimeout=0&j=false
- zlibCompressionLevel
const Int? zlibCompressionLevel
The compression level (0 - 9) to use with zlib (0 = No compression, 1 = Best speed, 9 = Best compression).
null
indicates a default value will be used.mongodb://example.com/puppies?zlibCompressionLevel=8