- Reference >
- Database Commands >
- touch
touch¶
-
touch
¶ New in version 2.2.
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. Thetouch
command has the following prototypical form:By default,
data
andindex
are false, andtouch
will perform no operation. For example, to load both the data and the index for a collection namedrecords
, you would use the following command in themongo
shell:touch
will not block read and write operations on amongod
, and can run on secondary members of replica sets.Note
Using
touch
to control or tweak what amongod
stores in memory may displace other records data in memory and hinder performance. Use with caution in production systems.Warning
If you run
touch
on a secondary, the secondary will enter aRECOVERING
state to prevent clients from sending read operations during thetouch
operation. Whentouch
finishes the secondary will automatically return toSECONDARY
state. Seestate
for more information on replica set member states.