How to change the compression of one existing collection?

1,912 views
Skip to first unread message

Matthieu Rigal

unread,
Apr 25, 2016, 6:22:13 AM4/25/16
to mongodb-user
Hi all,

I have a DB with several (quite big) collections, on Mongo 3.2.5 and WiredTiger with snappy compression on. 
I would like to change the compression setting on one small collection I have to test it uncompressed. Is there a possibility to do that on a secondary without having to resync the whole DB?

Best,
Matthieu

Kevin Adistambha

unread,
May 2, 2016, 3:11:34 AM5/2/16
to mongodb-user

Hi Matthieu,

I have a DB with several (quite big) collections, on Mongo 3.2.5 and WiredTiger with snappy compression on.

I would like to change the compression setting on one small collection I have to test it uncompressed. Is there a possibility to do that on a secondary without having to resync the whole DB?

It is not possible to change the block_compressor option of an existing collection.

However, you can create a new collection with the required options and replace the old collection:

  1. Create a new collection with the parameters you need, as described in the Specify Storage Engine Options page. E.g.: db.createCollection( "uncompressed", { storageEngine: { wiredTiger: { configString: 'block_compressor=none' }}})
  2. Copy all data from the existing collection into the new collection. Note: Please refrain from adding new data into the old collection during this stage.
  3. Drop the old collection and rename the new collection using db.collection.renameCollection(), so that the new collection replaces the old collection.

Please note that by setting a custom field in the collection’s block_compressor setting, this setting will be permanently set on the collection and cannot be overridden.

Is there a possibility to do that on a secondary without having to resync the whole DB?

It is possible to mix different storage engines in a replica set, but it is currently not possible (as of MongoDB 3.2) to set different storage engine options for a collection in a replica set. I.e., if you custom-specify a collection to use no compressor, the collection will not be using compression across all secondaries as well (since collection creation options are replicated to the secondaries, and cannot be changed once the collection is created).

Best regards,
Kevin

Matthieu Rigal

unread,
May 11, 2016, 12:03:23 PM5/11/16
to mongodb-user
Thanks for the detailed answer Kevin !
Reply all
Reply to author
Forward
0 new messages