@@ -53,8 +53,9 @@ class Count implements Executable
5353 * This is not supported for server versions < 3.4 and will result in an
5454 * exception at execution time if used.
5555 *
56- * * hint (string|document): The index to use. If a document, it will be
57- * interpretted as an index specification and a name will be generated.
56+ * * hint (string|document): The index to use. Specify either the index
57+ * name as a string or the index key pattern as a document. If specified,
58+ * then the query system will only consider plans using the hinted index.
5859 *
5960 * * limit (integer): The maximum number of documents to count.
6061 *
@@ -87,14 +88,8 @@ public function __construct($databaseName, $collectionName, $filter = [], array
8788 throw InvalidArgumentException::invalidType ('"collation" option ' , $ options ['collation ' ], 'array or object ' );
8889 }
8990
90- if (isset ($ options ['hint ' ])) {
91- if (is_array ($ options ['hint ' ]) || is_object ($ options ['hint ' ])) {
92- $ options ['hint ' ] = \MongoDB \generate_index_name ($ options ['hint ' ]);
93- }
94-
95- if ( ! is_string ($ options ['hint ' ])) {
96- throw InvalidArgumentException::invalidType ('"hint" option ' , $ options ['hint ' ], 'string or array or object ' );
97- }
91+ if (isset ($ options ['hint ' ]) && ! is_string ($ options ['hint ' ]) && ! is_array ($ options ['hint ' ]) && ! is_object ($ options ['hint ' ])) {
92+ throw InvalidArgumentException::invalidType ('"hint" option ' , $ options ['hint ' ], 'string or array or object ' );
9893 }
9994
10095 if (isset ($ options ['limit ' ]) && ! is_integer ($ options ['limit ' ])) {
@@ -177,7 +172,11 @@ private function createCommand()
177172 $ cmd ['collation ' ] = (object ) $ this ->options ['collation ' ];
178173 }
179174
180- foreach (['hint ' , 'limit ' , 'maxTimeMS ' , 'skip ' ] as $ option ) {
175+ if (isset ($ this ->options ['hint ' ])) {
176+ $ cmd ['hint ' ] = is_array ($ this ->options ['hint ' ]) ? (object ) $ this ->options ['hint ' ] : $ this ->options ['hint ' ];
177+ }
178+
179+ foreach (['limit ' , 'maxTimeMS ' , 'skip ' ] as $ option ) {
181180 if (isset ($ this ->options [$ option ])) {
182181 $ cmd [$ option ] = $ this ->options [$ option ];
183182 }
0 commit comments