翻译或纠错本页面
- Reference >
- mongo Shell Methods >
- Cursor Methods >
- cursor.hint()
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.
Behavior¶
When an index filter exists for the query shape, MongoDB ignores the hint(). The explain.filterSet field of the explain() output indicates whether MongoDB applied an index filter for the query.
You cannot use hint() if the query includes a $text query expression.