gpt4 book ai didi

c# - 使用 MongoDatabase 类而不是 MongoDatabaseImpl

转载 作者:可可西里 更新时间:2023-11-01 09:56:45 28 4
gpt4 key购买 nike

我需要通过 Mongo C# 驱动程序设置分析级别。

Client.GetDatabase("test") 返回 IMongoDatabase 接口(interface),该接口(interface)在运行时解析为 MongoDB.Driver.MongoDatabaseImpl

根据 MongoDB .NET Driver API Documentation MongoDatase 类有一个 SetProfilingLevel 方法,我无法在运行时对其进行转换。

顺便说一句,自 documentation 以来,我还安装了 Legacy Driver 版本 2.0.1|说里面有 SetProfilingLevel 方法。

最佳答案

新的 MongoDB 驱动程序(至少 2.3)没有更改分析级别的特定方法。
但是您可以使用 RunCommandAsync 执行任何命令。

public async Task SetProfilingLevelAsync(IMongoDatabase database, int level)
{
var command = new BsonDocumentCommand<BsonDocument>(new BsonDocument("profile", level));
await database.RunCommandAsync(command);
}

关于c# - 使用 MongoDatabase 类而不是 MongoDatabaseImpl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40821130/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com