This version of the documentation is archived and no longer
supported. View the current documentation to learn how to
upgrade your version of MongoDB.
- $hint
- Note- Deprecated since v3.2- Starting in v3.2, the - $hintoperator is deprecated in the- mongoshell. In the- mongoshell, use- cursor.hint()instead.- The - $hintoperator forces the query optimizer to use a specific index to fulfill the query. Specify the index either by the index name or by document.- Use - $hintfor testing query performance and indexing strategies. The- mongoshell provides a helper method- hint()for the- $hintoperator.- Consider the following operation: - db.users.find().hint( { age: 1 } ) - This operation returns all documents in the collection named - usersusing the index on the- agefield.- You can also specify a hint using either of the following forms: - db.users.find()._addSpecial( "$hint", { age : 1 } ) - db.users.find( { $query: {}, $hint: { age : 1 } } ) - Note- When an index filter exists for the query shape, MongoDB ignores the - $hint.