Platforms to show: All Mac Windows Linux Cross-Platform

Back to MongoClientMBS class.

MongoClientMBS.Collection(DatabaseName as String, CollectionName as String) as MongoCollectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get a newly allocated MongoCollectionMBS for the collection named collection in the named database.

Collections are automatically created on the MongoDB server upon insertion of the first document. There is no need to create a collection manually.

MongoClientMBS.Constructor(URI as MongoURIMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new client using the URI provided.

In case of an error, raises MongoExceptionMBS.

Connection is made when you run the first command, so you may want to soon query something or run a ping command.

MongoClientMBS.Database(Name as String) as MongoDatabaseMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Opens the given database.

Databases are automatically created on the MongoDB server upon insertion of the first document into a collection. There is no need to create a database manually.

MongoClientMBS.DatabasesNames(OptionsJSON as String = "") as String()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries the MongoDB server for a list of known databases.
Example

const URL = "mongodb://localhost/"

dim uri as new MongoURIMBS(URL)
dim client as new MongoClientMBS(uri)

dim databases() as string = client.DatabasesNames

Break // shows e.g. admin, config and local.

Returns a list of database names.
In case of an error, raises MongoExceptionMBS.

Some examples using this method:

MongoClientMBS.DefaultDatabase as MongoDatabaseMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Opens default database.

Get the database named in the MongoDB connection URI, or "" if the URI specifies none.
Useful when you want to choose which database to use based only on the URI in a configuration file.

MongoClientMBS.FindDatabases(OptionsJSON as String = "") as MongoCursorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Fetches list of database records.

Fetches a cursor containing documents, each corresponding to a database on this MongoDB server.

Sets current cursor.

Some examples using this method:

MongoClientMBS.NewCursorFromCommandReply(commandReplyJSON as String, OptionsJSON as String = "") as MongoCursorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a cursor object from the reply of a command.

Some MongoDB commands return a “cursor” document.

commandReplyJSON: The reply to a command, such as “aggregate”, “find”, or “listCollections”, that returns a cursor document.

MongoClientMBS.Ping

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 23.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sends ping command.

Great to check if connection is there and/or trigger reconnection.

MongoClientMBS.ServerDescription(ServerID as UInt32) as MongoServerDescriptionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get information about the server specified by ServerID.
Example

Const URL = "mongodb://localhost/"

Dim uri As New MongoURIMBS(URL)
Dim client As New MongoClientMBS(uri)

// do something to trigger connection
Dim names() As String = client.DatabasesNames

// now check first server
Dim des As MongoServerDescriptionMBS = client.ServerDescription(1)
Break // check in debugger

MongoClientMBS.ServerDescriptions as MongoServerDescriptionMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Fetches an server descroptions for all known servers in the topology.
Example

Const URL = "mongodb://localhost/"

Dim uri As New MongoURIMBS(URL)
Dim client As New MongoClientMBS(uri)

// do something to trigger connection
Dim names() As String = client.DatabasesNames

// now check first server
Dim ServerDescriptions() As MongoServerDescriptionMBS = client.ServerDescriptions
Break // check in debugger

Returns no servers until the client connects. Returns a single server if the client is directly connected, or all members of a replica set if the client’s MongoDB URI includes a “replicaSet” option, or all known mongos servers if the MongoDB URI includes a list of them.

MongoClientMBS.Watch(pipelineJSON as String, OptionsJSON as String = "") as MongoChangeStreamMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 23.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a change stream for a client.

It is preferred to call this function over using a raw aggregation to create a change stream.

This function uses the read preference and read concern of the client. If the change stream needs to re-establish connection, the same read preference will be used. This may happen if the change stream encounters a resumable error.

Warning A change stream is only supported with majority read concern.
This function is considered a retryable read operation. Upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. If retryreads is false in the URI the retry behavior does not apply.

Call this method on the client which the change stream listens to.

pipelineJSON: A JSON representing an aggregation pipeline appended to the change stream. This may be an empty document.

OptionsJSON: A JSON containing change stream options. options may be "" or a JSON document with additional command options:

batchSize: An integer representing number of documents requested to be returned on each call to NextChange()

resumeAfter: A Document representing the logical starting point of the change stream. The result of StreamResumeToken() or the _id field of any change received from a change stream can be used here. This option is mutually exclusive with startAfter and startAtOperationTime.

startAfter: A Document representing the logical starting point of the change stream. Unlike resumeAfter, this can resume notifications after an “invalidate” event. The result of StreamResumeToken() or the _id field of any change received from a change stream can be used here. This option is mutually exclusive with resumeAfter and startAtOperationTime.

startAtOperationTime: A Timestamp. The change stream only provides changes that occurred at or after the specified timestamp. Any command run against the server will return an operation time that can be used here. This option is mutually exclusive with resumeAfter and startAfter.

maxAwaitTimeMS: An int64 representing the maximum amount of time a call to StreamResumeToken() will block waiting for data

fullDocument: An optional UTF-8 string. Set this option to “default”, “updateLookup”, “whenAvailable”, or “required”, If unset, The string “default” is assumed. Set this option to “updateLookup” to direct the change stream cursor to lookup the most current majority-committed version of the document associated to an update change stream event.

fullDocumentBeforeChange: An optional UTF-8 string. Set this option to “whenAvailable”, “required”, or “off”. When unset, the default value is “off”. Similar to “fullDocument”, but returns the value of the document before the associated change.

comment: A JSON specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Only string values are supported prior to MongoDB 4.4.

The items on this page are in the following plugins: MBS MongoDB Plugin.


The biggest plugin in space...