- Reference >
- Database Commands >
- Administration Commands >
- collMod
collMod¶
-
collMod¶ New in version 2.2.
collModmakes it possible to add flags to a collection to modify the behavior of MongoDB. Flags includeusePowerOf2Sizesandindex. 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
userFlagsfield in the indb.collection.stats()output to check enabled collection flags.-
usePowerOf2Sizes¶ The
usePowerOf2Sizesflag 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.Note
With
usePowerOf2Sizes, MongoDB allocates records that have power of 2 sizes until record sizes equal 4 megabytes. For records larger than 4 megabytes withusePowerOf2Sizesset,mongodwill allocate records in full megabytes by rounding up to the nearest megabyte.usePowerOf2Sizesis 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
usePowerOf2Sizeson the collection namedproducts, use the following operation:To disable
usePowerOf2Sizeson the collectionproducts, use the following operation:Warning
Changed in version 2.2.1:
usePowerOf2Sizesnow supports documents larger than 8 megabytes. If you enableusePowerOf2Sizesyou must use at least version 2.2.1.usePowerOf2Sizesonly affects subsequent allocations caused by document insertion or record relocation as a result of document growth, and does not affect existing allocations.
-
index¶ The
indexflag changes the expiration time of a TTL Collection.Specify the key and new expiration time with a document of the form:
where
<index_spec>is an existing index in the collection andsecondsis the number of seconds to subtract from the current time.Example
To update the expiration value for a collection named
sessionsindexed on alastAccessfield from 30 minutes to 60 minutes, use the following operation:Which will return the document:
On success
collModreturns a document with fieldsexpireAfterSeconds_oldandexpireAfterSeconds_newset to their respective values.On failure,
collModreturns a document withno expireAfterSeconds field to updateif there is no existingexpireAfterSecondsfield orcannot find index { **key**: 1.0 } for ns **namespace**if the specifiedkeyPatterndoes not exist.
-