On this page


The touch command loads data from the data storage layer into memory. touch can load the data (i.e. documents) indexes or both documents and indexes. Use this command to ensure that a collection, and/or its indexes, are in memory before another operation. By loading the collection or indexes into memory, mongod will ideally be able to perform subsequent operations more efficiently. The touch command has the following prototypical form:

{ touch: [collection], data: [boolean], index: [boolean] }

By default, data and index are false, and touch will perform no operation. For example, to load both the data and the index for a collection named records, you would use the following command in the mongo shell:

db.runCommand({ touch: "records", data: true, index: true })

touch will not block read and write operations on a mongod, and can run on secondary members of replica sets.

The command can also take the following options:

Option Type Description
txnNumber 64-bit integer/long


A strictly increasing non-negative number that uniquely identifies the command in the command’s session.

If specified, the command must also include the lsid option.

New in version 3.6.

lsid Document


The document that specifies the unique id of the session associated with the command. If the txnNumber is specified, the lsid is required.


The mongo shell and the drivers provide helpers to start the session and set the lsid for the commands.

New in version 3.6.


Performance Impact

Using touch to control or tweak what a mongod stores in memory may displace other records data in memory and hinder performance. Use with caution in production systems.

Replication and Secondaries

If you run touch on a secondary, the secondary will enter a RECOVERING state to prevent clients from sending read operations during the touch operation. When touch finishes the secondary will automatically return to SECONDARY state. See state for more information on replica set member states.

Storage Engines

Changed in version 3.0.0.

If the current storage engine does not support touch, the touch command will return an error.

The MMAPv1 storage engine supports touch.

The WiredTiger storage engine does not support touch.