C# mongo driver with multiple mongo client instance

22 hours ago 1
ARTICLE AD BOX

I'm writing an ASP.NET Core application, using Mongo driver 3.5.2.

As I notice, when I need to register class mapping, this is what I need to do:

if (!BsonClassMap.IsClassMapRegistered(typeof(MyEntity))) { BsonClassMap.RegisterClassMap<MyEntity>(cm => { cm.AutoMap(); }); }

The C# driver uses BsonClassMap which is a global class.

Let's say I have 2 Mongo database collections main-db and old-db which have the same collection of MyEntity with different mapping. The old-db has legacy id while main-db has standard id.

Using BsonClassMap will affect to both MongoCollection.

Is there any solution that I can provide custom deserialization for each MongoCollection ?

I don't understand why the Mongo team does not provide options while configuring MongoClient, so it will be more customizable.

Thanks

Read Entire Article