OPTIONS

cursor.hint()

Definition

cursor.hint(index)

Call this method on a query to override MongoDB’s default index selection and query optimization process. Use db.collection.getIndexes() to return the list of current indexes on a collection.

The cursor.hint() method has the following parameter:

Parameter Type Description
index string or document The index to “hint” or force MongoDB to use when performing the query. Specify the index either by the index name or by the index specification document.

See

Indexing Tutorials for information.

Example

The following example returns all documents in the collection named users using the index on the age field.

db.users.find().hint( { age: 1 } )

You can also specify the index using the index name:

db.users.find().hint( "age_1" )

See also

$hint