rebus-org / Rebus.MongoDb

:bus: MongoDB persistence implementations for Rebus
https://mookid.dk/category/rebus
Other
5 stars 6 forks source link

MarkAsComplete throws an Error if GUID uses BsonType.String #3

Closed cgehrmann closed 4 years ago

cgehrmann commented 4 years ago

In our application uses a GuidSerializer with String representation.

BsonSerializer.RegisterSerializer(typeof(Guid), new GuidSerializer(BsonType.String));

In this case the filter does not work correctly and no data records are found and an exception is thrown.

After a littlebit of debugging the MongoDbSagaStorage, I found a working solution.

Instead of

var result = await collection.DeleteManyAsync(new BsonDocument("_id", sagaData.Id)).ConfigureAwait(false);

I used

var criteria = Builders<BsonDocument>.Filter.Eq("_id", Data.Id);
var result = await collection.DeleteManyAsync(criteria).ConfigureAwait(false);

and the saga was correctly deleted.

mookid8000 commented 4 years ago

hi @cgehrmann , I've made an attempt to fix it in Rebus.MongoDb 5.1.0-b1, which is available on NuGet.org in a few minutes.

Could you try that and see if it solves your problem?

Please report back here 🙂 if it works, I'll release it as a pure 5.1.0

cgehrmann commented 4 years ago

hi @mookid8000,

thanks for the quick work. Now everything works as expected.

Sage was successfully deleted on MarkAsComplete

Chris

mookid8000 commented 4 years ago

Perfect 🙂 I've pushed Rebus.MongoDb 5.1.0 to NuGet.org now

Thanks for reporting the issue and providing a fix!