|
This is not possible because serialization is a general purpose mechanism that is handled at a lower level than the driver (IMongoDatabase is defined in MongoDB.Driver.dll but IBsonSerializer is in MongoDB.Bson.dll).
My recommendation is that you not think about trying to access a database from a Serialize or Deserialize method. Serialization should be a pure data conversion from one representation to another (e.g. from in-memory to BSON) and should not require access to any database.
You could create a custom serializer and pass in a reference to an IMongoDatabase to your custom serializer's constructor (so it would be part of the state of serializer), but still I don't recommend it.
|