-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
FeatureNew feature or requestNew feature or request
Description
MongoDB API exposes users to data loss due to the way the shared transaction API is designed. Take for example the following snippet:
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
var session = context.SynchronizedStorageSession.GetClientSession();
var collection = session.Client.GetDatabase("mydatabase").GetCollection<MyBusinessObject>("mycollection");
return collection.InsertOneAsync(session, new MyBusinessObject());
}
The last line is really easy to get wrong:
return collection.InsertOneAsync(session, new MyBusinessObject());
The InsertOneAsync method has many overloads one of which is very similar to the above one but doesn't take a session parameter as the first argument. If a customer writes the aforementioned snippet like follows:
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
var session = context.SynchronizedStorageSession.GetClientSession();
var collection = session.Client.GetDatabase("mydatabase").GetCollection<MyBusinessObject>("mycollection");
return collection.InsertOneAsync(new MyBusinessObject());
}
it compiles fine and it might also work, however the MyBusinessObject save attempt is not included in the shared transaction created by the endpoint.
It would be nice to add to the MongoDB package an analyzer to detect and warn users in case such a mistake is done.
Metadata
Metadata
Assignees
Labels
FeatureNew feature or requestNew feature or request