ZStandard Compression not working in MongoDB v4.2.7

836 Views Asked by At
  • Setup:

I'm using MongoDB v4.2.7 along with the .Net MongoDB driver v2.11.0(beta v) on a windows 10 machine.

  • Code
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);
  • Config

I've edited my mongod.cfg file as follows:

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

After the collection and the documents are added successfully I ran the db.printCollectionStats() on the mongo shell and I got block_compressor=snappy in the WiredTiger section while it should be block_compressor=zstd.

Below is a screenshot of the db.Stats(1024*1024*1024) output as well "dataSize" : 0.08773485571146011 and "storageSize" : 0.009387969970703125

1

There are 1 best solutions below

0
On

I posted a question on MongoDB Developer community Forums and was advised that my c# code was setting Network Compression rather than block_compressor.

This is the correct c# code that worked for me:

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");

Kind regards.