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.Command(dbName as String, commandJSON as String) as String   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
This is a simplified interface to CommandQuery.

It returns the first document from the result cursor into reply. The client’s read preference, read concern, and write concern are not applied to the command.

This function is not considered a retryable read operation.

See also:

MongoClientMBS.Command(dbName as String, commandJSON as String, OptionsJSON as String) as String   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Execute a command on the server, interpreting options according to the MongoDB server version.

To send a raw command to the server without any of this logic, use Command().

Read preferences, read and write concern, and collation can be overridden by various sources.

See also:

MongoClientMBS.CommandQuery(dbName as String, queryJSON as String) as MongoCursorMBS   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a query cursor.

This function creates a cursor which will execute the command when Next on the cursor is called on it. The client’s read preference, read concern, and write concern are not applied to the command, and Next on the cursor will not check the server response for a write concern error or write concern timeout.

MongoClientMBS.CommandWithServerId(dbName as String, commandJSON as String, serverId as UInt32) as String   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
This function executes a command on a specific server, using the database and command specification provided.

This function is not considered a retryable read operation.

dbName: The name of the database to run the command on.
serverId: An opaque id specifying which server to use.

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/"

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

Var 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.ReadCommand(dbName as String, commandJSON as String, OptionsJSON as String = "") as String   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Execute a command on the server, applying logic that is specific to commands that read, and taking the MongoDB server version into account.

To send a raw command to the server without any of this logic, use Command().

Use this function for commands that read such as “count” or “distinct”.

Read preferences, read concern, and collation can be overridden by various sources. In a transaction, read concern and write concern are prohibited in opts and the read preference must be primary or nil. The highest-priority sources for these options are listed first in the following table. No write concern is applied.

MongoClientMBS.ReadWriteCommand(dbName as String, commandJSON as String, OptionsJSON as String = "") as String   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Execute a command on the server, applying logic for commands that both read and write, and taking the MongoDB server version into account.

To send a raw command to the server without any of this logic, use Command().

Use this function for commands that both read and write, such as “mapReduce” with an output collection.

Read and write concern and collation can be overridden by various sources. In a transaction, read concern and write concern are prohibited in opts. The highest-priority sources for these options are listed first in the following table. Read preferences are not applied. The write concern is omitted for MongoDB before 3.4.

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/"

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

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

// now check first server
Var 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/"

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

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

// now check first server
Var 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.

MongoClientMBS.WriteCommand(dbName as String, commandJSON as String, OptionsJSON as String = "") as String   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Execute a command on the server, applying logic that is specific to commands that write, and taking the MongoDB server version into account.

To send a raw command to the server without any of this logic, use Command().

Use this function for commands that write such as “drop” or “createRole” (but not for “insert”, “update”, or “delete”, see Basic Write Operations). Write concern and collation can be overridden by various sources. In a transaction, read concern and write concern are prohibited in opts. The highest-priority sources for these options are listed first in the following table. The write concern is omitted for MongoDB before 3.4.

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


The biggest plugin in space...