- Reference >
- Database Commands >
- Administration Commands >
- collMod
collMod¶
On this page
Definition¶
-
collMod
¶ collMod
makes it possible to add flags to a collection to modify the behavior of MongoDB. Flags includeusePowerOf2Sizes
andindex
. 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 thedb.collection.stats()
output to check enabled collection flags.
Flags¶
TTL Collection Expiration Time¶
-
index
¶ The
index
flag changes the expiration time of a TTL Collection.Specify the key and new expiration time with a document of the form:
In this example,
<index_spec>
is an existing index in the collection andseconds
is the number of seconds to subtract from the current time.On success
collMod
returns a document with fieldsexpireAfterSeconds_old
andexpireAfterSeconds_new
set to their respective values.On failure,
collMod
returns a document withno expireAfterSeconds field to update
if there is no existingexpireAfterSeconds
field orcannot find index { **key**: 1.0 } for ns **namespace**
if the specifiedkeyPattern
does not exist.
Record Allocation¶
Disable All Record Padding¶
-
noPadding
¶ New in version 3.0.0.
noPadding
flag is available for the MMAPv1 storage engine only.noPadding
disables record padding for the collection. Without padding, the record allocation size corresponds to the document size, and any updates that results in document growth will require a new allocation.Warning
Only set
noPadding
totrue
for collections whose workloads have no update operations that cause documents to grow, such as for collections with workloads that are insert-only. For more information, see No Padding Allocation Strategy.
Powers of Two Record Allocation¶
-
usePowerOf2Sizes
¶ Deprecated since version 3.0.0.
usePowerOf2Sizes
flag is available for the MMAPv1 storage engine only.usePowerOf2Sizes
has no effect on the allocation strategy. MongoDB 3.0 uses the power of 2 allocation as the default record allocation strategy for MMAPv1.To disable the power of 2 allocation for a collection, use the
collMod
command with thenoPadding
flag or thedb.createCollection()
method with thenoPadding
option. For more information, see MMAPv1 Record Allocation Behavior Changes.
Example: Change Expiration Value for Indexes¶
To update the expiration value for a collection
named sessions
indexed on a lastAccess
field from 30
minutes to 60 minutes, use the following operation:
Which will return the document: