How to get the compression type of a MongoDB collection ?!
To specify compression for specific collections, you’ll need to override the defaults by passing the appropriate options in the db.createCollection() command. For example, to create a collection called “myNewCol” using the zlib compression library:
db.createCollection( “myNewCol”, { storageEngine: { wiredTiger: { configString: ‘block_compressor=zlib’ }}})
#./mongo localhost:27010/dbversity
MongoDB shell version: 3.2.0
connecting to: localhost:27010/dbversity
rs1:PRIMARY>
rs1:PRIMARY>
rs1:PRIMARY>
rs1:PRIMARY> use newdb1
switched to db newdb1
rs1:PRIMARY>
rs1:PRIMARY> db.createCollection( “myNewCol”, { storageEngine: { wiredTiger: { configString: ‘block_compressor=zlib’ }}})
{ “ok” : 1 }
rs1:PRIMARY>
rs1:PRIMARY> db.myNewCol.stats().wiredTiger.creationString
allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=zlib,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=0,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u
rs1:PRIMARY>
// from the above output, observe block_compressor=zlib
rs1:PRIMARY> for(var i = 1; i <= 10000 ; i++){db.myNewCol.insert({“id” : i , “name” : “bulk-inserts”, ” Iteration: ” : i });}
WriteResult({ “nInserted” : 1 })
rs1:PRIMARY>
rs1:PRIMARY> db.stats(1024*1024).dataSize + db.stats(1024*1024).indexSize
0.7573089599609375
rs1:PRIMARY>
rs1:PRIMARY> use newdb2
switched to db newdb2
rs1:PRIMARY>
rs1:PRIMARY> db.createCollection(“myCol_wo_cmprsn”)
{ “ok” : 1 }
rs1:PRIMARY>
rs1:PRIMARY> db.myCol_wo_cmprsn.stats().wiredTiger.creationString
allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=0,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=0,extractor=,format=btree,huffman_key=,huffman_value=,immutable=0,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=),lsm=(auto_throttle=,bloom=,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=0,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=0,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u
rs1:PRIMARY>
// from the above output, observe block_compressor=snappy
rs1:PRIMARY> for(var i = 1; i <= 10000 ; i++){db.myCol_wo_cmprsn.insert({“id” : i , “name” : “bulk-inserts”, ” Iteration: ” : i });}
WriteResult({ “nInserted” : 1 })
rs1:PRIMARY>
rs1:PRIMARY> db.stats(1024*1024).dataSize + db.stats(1024*1024).indexSize
0.7573089599609375
rs1:PRIMARY>
But I wanted to understand how come both snappy & zlip compression cosumes the same space for same inserts ? Any ideas !