On this page
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. The
touchcommand has the following prototypical form:
indexare false, and
touchwill 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
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.