Platforms to show: All Mac Windows Linux Cross-Platform

Back to MongoDatabaseMBS class.

MongoDatabaseMBS.Aggregate(pipelineJSON as String, OptionsJSON as String = "") as MongoCursorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 23.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an aggregate database.
Example

dim database as MongoDatabaseMBS // your database

dim Cursor as MongoCursorMBS = database.Aggregate("[{""$listLocalSessions"": {}}]")
// loop over cursor

This function creates a cursor which sends the aggregate command on the underlying database upon the first call to MongoDB.CursorNext. For more information on building aggregation pipelines, see the MongoDB Manual entry on the aggregate command. Note that the pipeline must start with a compatible stage that does not require an underlying collection (e.g. “$currentOp”, “$listLocalSessions”).
Returns a new cursor on success.

Please review the documentation for MongoDB on how to build the JSON for pipeline or options.

In case of an error, raises MongoExceptionMBS.

MongoDatabaseMBS.Collection(Name 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
Gets the collection with given name.

MongoDatabaseMBS.CollectionNames(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
Fetches the list of the names of all of the collections in database.
Example

const URL = "mongodb://192.168.2.102/"

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

dim database as MongoDatabaseMBS = client.Database("local")
dim Collections() as string = database.CollectionNames

Break // see in debugger

see MongoDB documentation for list of options:
https://www.mongodb.com/docs/manual/reference/command/listCollections/

In case of an error, raises MongoExceptionMBS.

MongoDatabaseMBS.Command(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 Command() that returns the first result document.
Example
Const URL = "mongodb://localhost/"

Dim uri As New MongoURIMBS(URL)
Dim client As New MongoClientMBS(uri)
Dim database As MongoDatabaseMBS = client.Database("local")

Dim ping As New JSONItem
ping.Value("ping") = 1

Dim reply As String = database.Command(ping.ToString)

Break // { "ok" : 1.0 }

The database’s read preference, read concern, and write concern are not applied to the command. The parameter reply is initialized even upon failure to simplify memory management.

This function is not considered a retryable read operation.

See also:

MongoDatabaseMBS.Command(commandJSON as String, 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
Execute a command on the server, interpreting opts according to the MongoDB server version.
Example
Const URL = "mongodb://localhost/"

Dim uri As New MongoURIMBS(URL)
Dim client As New MongoClientMBS(uri)
Dim database As MongoDatabaseMBS = client.Database("local")

Dim ping As New JSONItem
ping.Value("ping") = 1

Dim options As New JSONItem

Dim reply As String = database.Command(ping.ToString, options.tostring)

Break // { "ok" : 1.0 }

Returns the reply from the server.

In case of an error, raises MongoExceptionMBS.

See also:

MongoDatabaseMBS.Constructor   Private

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The private constructor.

MongoDatabaseMBS.Copy as MongoDatabaseMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Performs a deep copy of the database struct and its configuration.

MongoDatabaseMBS.CreateCollection(Name as String, OptionsJSON 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
Creates a collection in the database.
Example

const URL = "mongodb://localhost/"

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

dim database as MongoDatabaseMBS = client.Database("local")
dim Collection as MongoCollectionMBS = database.CreateCollection("testing2")

MessageBox Collection.Name

Break

If no write concern is provided in opts, the database’s write concern is used.

For a list of all options, see the MongoDB Manual entry on the create command.
In case of an error, raises MongoExceptionMBS.

MongoDatabaseMBS.FindCollections(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 a cursor containing documents, each corresponding to a collection on this database.
Example

const URL = "mongodb://localhost/"

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

dim database as MongoDatabaseMBS = client.Database("local")

dim cursor as MongoCursorMBS = database.FindCollections
dim Record as string

while cursor.NextRecord(record)

MessageBox record

wend

Break

In case of an error, raises MongoExceptionMBS.

Some examples using this method:

MongoDatabaseMBS.HasCollection(Name as String) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Checks to see if a collection exists on the MongoDB server within database.

If the function succeeds, it returns true if the collection exists and false if not.
Raises exception in case of an invalid arguments or a server or network error.

In case of an error, raises MongoExceptionMBS.

MongoDatabaseMBS.ReadCommand(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.

MongoDatabaseMBS.ReadWriteCommand(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.

MongoDatabaseMBS.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 database.

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 database. 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 database 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.

MongoDatabaseMBS.WriteCommand(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”). 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...