I’m currently experimenting with transactions and experiencing some issues which raised the following questions:
- Should a document be inserted inside a transaction without calling CommitTransaction?
- If the above is true, should a document be removed which was inserted in the same transaction when calling AbortTransaction?
My implementation with the latest MongoDB.Driver (2.10.4) looks as follows:
var client = new MongoClient(...);
var database = client.GetDatabase("db1");
var session = client.StartSession();
var options = new TransactionOptions(ReadConcern.Local, ReadPreference.Primary, WriteConcern.W1);
session.StartTransaction(options);
var collection = database.GetCollection<ConnectionEntity>("connections");
var newConnection = new ConnectionEntity()
{
Id = "1234",
Name = "test1234"
};
collection.InsertOne(newConnection);
session.AbortTransaction();
I expected that the new document should not be inserted in the first place or should be removed after calling AbortTransaction.
Any hints would be much appreciated.