27
27
use MongoDB \Exception \UnsupportedException ;
28
28
use function is_array ;
29
29
use function is_object ;
30
+ use function is_string ;
30
31
use function MongoDB \server_supports_feature ;
31
32
32
33
/**
@@ -43,6 +44,9 @@ class Delete implements Executable, Explainable
43
44
/** @var integer */
44
45
private static $ wireVersionForCollation = 5 ;
45
46
47
+ /** @var int */
48
+ private static $ wireVersionForHint = 9 ;
49
+
46
50
/** @var string */
47
51
private $ databaseName ;
48
52
@@ -68,6 +72,13 @@ class Delete implements Executable, Explainable
68
72
* This is not supported for server versions < 3.4 and will result in an
69
73
* exception at execution time if used.
70
74
*
75
+ * * hint (string|document): The index to use. Specify either the index
76
+ * name as a string or the index key pattern as a document. If specified,
77
+ * then the query system will only consider plans using the hinted index.
78
+ *
79
+ * This is not supported for server versions < 4.4 and will result in an
80
+ * exception at execution time if used.
81
+ *
71
82
* * session (MongoDB\Driver\Session): Client session.
72
83
*
73
84
* Sessions are not supported for server versions < 3.6.
@@ -97,6 +108,10 @@ public function __construct($databaseName, $collectionName, $filter, $limit, arr
97
108
throw InvalidArgumentException::invalidType ('"collation" option ' , $ options ['collation ' ], 'array or object ' );
98
109
}
99
110
111
+ if (isset ($ options ['hint ' ]) && ! is_string ($ options ['hint ' ]) && ! is_array ($ options ['hint ' ]) && ! is_object ($ options ['hint ' ])) {
112
+ throw InvalidArgumentException::invalidType ('"hint" option ' , $ options ['hint ' ], ['string ' , 'array ' , 'object ' ]);
113
+ }
114
+
100
115
if (isset ($ options ['session ' ]) && ! $ options ['session ' ] instanceof Session) {
101
116
throw InvalidArgumentException::invalidType ('"session" option ' , $ options ['session ' ], Session::class);
102
117
}
@@ -130,6 +145,10 @@ public function execute(Server $server)
130
145
throw UnsupportedException::collationNotSupported ();
131
146
}
132
147
148
+ if (isset ($ this ->options ['hint ' ]) && ! server_supports_feature ($ server , self ::$ wireVersionForHint )) {
149
+ throw UnsupportedException::hintNotSupported ();
150
+ }
151
+
133
152
$ inTransaction = isset ($ this ->options ['session ' ]) && $ this ->options ['session ' ]->isInTransaction ();
134
153
if ($ inTransaction && isset ($ this ->options ['writeConcern ' ])) {
135
154
throw UnsupportedException::writeConcernNotSupportedInTransaction ();
@@ -170,6 +189,10 @@ private function createDeleteOptions()
170
189
$ deleteOptions ['collation ' ] = (object ) $ this ->options ['collation ' ];
171
190
}
172
191
192
+ if (isset ($ this ->options ['hint ' ])) {
193
+ $ deleteOptions ['hint ' ] = $ this ->options ['hint ' ];
194
+ }
195
+
173
196
return $ deleteOptions ;
174
197
}
175
198
0 commit comments