1
  • 设置:

我在 Windows 10 机器上使用 MongoDB v4.2.7 和 .Net MongoDB 驱动程序 v2.11.0(beta v)。

  • 代码
var mongoClientSettings = new MongoClientSettings();

mongoClientSettings.Compressors = new List<CompressorConfiguration>() {
       new CompressorConfiguration(CompressorType.ZStandard)
    };

var client = new MongoClient(mongoClientSettings);

IMongoDatabase testdb = client.GetDatabase("testdb");

var eaiRequestLogsCollection = testdb.GetCollection<EAIRequestsLogMDB>("EAIRequestsLogs");

eaiRequestLogsCollection.InsertMany(eAIRequestsLogMDBs);
  • 配置

我编辑了我的 mongod.cfg 文件,如下所示:

storage:
  dbPath: C:\Program Files\MongoDB\Server\4.2\data
  journal:
    enabled: true
  engine: "wiredTiger"
  wiredTiger:
      collectionConfig:
         blockCompressor: "zstd"
  • 问题:

成功添加集合和文档后,我db.printCollectionStats()在 mongo shell 上运行了,我进入block_compressor=snappy了 WiredTiger 部分,而它应该是block_compressor=zstd.

下面是 db.Stats(1024*1024*1024) 输出以及 “dataSize”的屏幕截图:0.08773485571146011 和“storageSize”:0.009387969970703125

4

1 回答 1

0

我在 MongoDB 开发人员社区论坛上发布了一个问题,并被告知我的 c# 代码设置了网络压缩而不是 block_compressor。

这是对我有用的正确 c# 代码:

var client = new MongoClient("mongodb://127.0.0.1:27017");
IMongoDatabase testdb = client.GetDatabase("testdb");

testdb.CreateCollection("EAIRequestsLogs", new CreateCollectionOptions()
 {
   StorageEngine = new BsonDocument 
   {
        { "wiredTiger", new BsonDocument 
           {
               {  "configString" , "block_compressor=zstd"}
           } 
        }
   }
 });
var eaiRequestLogsCollection = testdb.GetCollection<EAIRequestsLogMDB>("EAIRequestsLogs");

亲切的问候。

于 2020-06-10T07:24:00.370 回答