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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With