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.


The biggest plugin in space...