- Reference >
- Database Commands >
- Administration Commands >
- touch
touch¶
-
touch¶ New in version 2.2.
The
touchcommand loads data from the data storage layer into memory.touchcan 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,mongodwill ideally be able to perform subsequent operations more efficiently. Thetouchcommand has the following prototypical form:By default,
dataandindexare false, andtouchwill perform no operation. For example, to load both the data and the index for a collection namedrecords, you would use the following command in themongoshell:touchwill not block read and write operations on amongod, and can run on secondary members of replica sets.Note
Using
touchto control or tweak what amongodstores in memory may displace other records data in memory and hinder performance. Use with caution in production systems.Warning
If you run
touchon a secondary, the secondary will enter aRECOVERINGstate to prevent clients from sending read operations during thetouchoperation. Whentouchfinishes the secondary will automatically return toSECONDARYstate. Seestatefor more information on replica set member states.