- Reference >
- Database Commands >
- collMod
collMod¶
-
collMod
¶ New in version 2.2.
collMod
makes it possible to add flags to a collection to modify the behavior of MongoDB. In the current release the only available flag isusePowerOf2Sizes
. The command takes the following prototype form:In this command substitute
<collection>
with the name of a collection in the current database, and<flag>
and<value>
with the flag and value you want to set.Use the
userFlags
field in the indb.collection.stats()
output to check enabled collection flags.-
usePowerOf2Sizes
¶ The
usePowerOf2Sizes
flag changes the method that MongoDB uses to allocate space on disk for documents in this collection. By settingusePowerOf2Sizes
, you ensure that MongoDB will allocate space for documents in sizes that are powers of 2 (e.g. 4, 8, 16, 32, 64, 128, 256, 512…8388608). WithusePowerOf2Sizes
MongoDB will be able to more effectively reuse space.usePowerOf2Sizes
is useful for collections where you will be inserting and deleting large numbers of documents to ensure that MongoDB will effectively use space on disk.Example
To enable
usePowerOf2Sizes
on the collection namedproducts
, use the following operation:To disable
usePowerOf2Sizes
on the collectionproducts
, use the following operation:Warning
Changed in version 2.2.1:
usePowerOf2Sizes
now supports documents larger than 8 megabytes. If you enableusePowerOf2Sizes
you must use at least version 2.2.1.usePowerOf2Sizes
only affects subsequent allocations caused by document insertion or record relocation as a result of document growth, and does not affect existing allocations.Note
usePowerOf2Sizes
has no effect on capped collections.
-