Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MongoDatabase class instead of MongoDatabaseImpl

I need to set profiling level via Mongo C# Driver.

Client.GetDatabase("test") returns IMongoDatabase interface which resolves to MongoDB.Driver.MongoDatabaseImpl at runtime.

According to MongoDB .NET Driver API Documentation MongoDatase class has a SetProfilingLevel method which I can not cast to at runtime.

BTW I also installed Legacy Driver version 2.0.1 since documentation says that SetProfilingLevel method is in it.

like image 564
guneysus Avatar asked Dec 01 '25 09:12

guneysus


1 Answers

New MongoDB driver (at least 2.3) doesn't have specific method for changing profiling level.
But you can execute any command using RunCommandAsync.

public async Task SetProfilingLevelAsync(IMongoDatabase database, int level)
{
    var command = new BsonDocumentCommand<BsonDocument>(new BsonDocument("profile", level));
    await database.RunCommandAsync(command);
}
like image 192
rnofenko Avatar answered Dec 03 '25 23:12

rnofenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!