MongoSessionMBS methods

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

Back to MongoSessionMBS class.

MongoSessionMBS.AbortTransaction

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Abort a multi-document transaction.
Example

Dim Client as MongoClientMBS // your connection
Dim Collection as MongoClientMBS // your collection

// count before
Dim count1 As Integer = Collection.EstimatedDocumentCount

Dim session As New MongoSessionMBS(Client)
session.StartTransaction

Dim NewRecord As New JSONItem

NewRecord.Value("firstName") = "Bob"
NewRecord.Value("lastName") = "Jones"
NewRecord.Value("phone") = "555-1234-567"

Dim Result As String = Collection.InsertOne(NewRecord.toString)

// should be count1 + 1
Dim count2 As Integer = Collection.EstimatedDocumentCount

details.Text = result

session.AbortTransaction
Dim count3 As Integer = Collection.EstimatedDocumentCount
// should be back to count1

Break // see in debugger

Raises exception if there are invalid arguments, such as a session with no transaction in progress. Network or server errors are ignored.

Some examples using this method:

MongoSessionMBS.CommitTransaction as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Commit a multi-document transaction.
Example

Dim Client as MongoClientMBS // your connection
Dim Collection as MongoClientMBS // your collection

Dim session As New MongoSessionMBS(Client)

session.StartTransaction

Dim NewRecord As New JSONItem

NewRecord.Value("firstName") = "Bob"
NewRecord.Value("lastName") = "Jones"
NewRecord.Value("phone") = "555-1234-567"

Dim Result As String = Collection.InsertOne(NewRecord.toString)
Break // see in debugger

Returns JSON if the transaction was committed. Raises exception if there are invalid arguments, such as a session with no transaction in progress, or if there is a server or network error.

Some examples using this method:

MongoSessionMBS.Constructor(client as MongoClientMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a session for a sequence of operations.

MongoSessionMBS.StartTransaction

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Start a multi-document transaction for all following operations in this session.

The transaction must be completed with CommitTransaction or AbortTransaction. An in-progress transaction is automatically aborted by destructor.

Raises exception if there are invalid arguments, such as a session with a transaction already in progress.

If you run MongoDB server locally, you may need to configure a replication. Otherwise you get an error like this: "Error 17:20: Transaction numbers are only allowed on a replica set member or mongos".

Some examples using this method:

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


💬 Ask a question or report a problem