@@ -181,27 +181,51 @@ _mongoc_set_cursor_ns (mongoc_cursor_t *cursor,
181
181
}
182
182
183
183
184
- /* true if there are $ and non-$ keys. precondition: bson must be valid. */
184
+ /* true if there are $- keys. precondition: bson must be valid. */
185
185
static bool
186
- _mixed_dollar_non_dollar (const bson_t * bson )
186
+ _has_dollar_fields (const bson_t * bson )
187
187
{
188
188
bson_iter_t iter ;
189
- bool has_dollar = false;
190
- bool has_non_dollar = false;
191
189
const char * key ;
192
190
193
191
BSON_ASSERT (bson_iter_init (& iter , bson ));
194
192
while (bson_iter_next (& iter )) {
195
193
key = bson_iter_key (& iter );
196
194
197
195
if (key [0 ] == '$' ) {
198
- has_dollar = true;
199
- } else {
200
- has_non_dollar = true;
196
+ return true;
201
197
}
202
198
}
203
199
204
- return has_dollar && has_non_dollar ;
200
+ return false;
201
+ }
202
+
203
+
204
+ /* true if there are any non-$ keys. precondition: bson must be valid. */
205
+ static bool
206
+ _has_nondollar_fields (const bson_t * bson )
207
+ {
208
+ bson_iter_t iter ;
209
+ const char * key ;
210
+
211
+ BSON_ASSERT (bson_iter_init (& iter , bson ));
212
+ while (bson_iter_next (& iter )) {
213
+ key = bson_iter_key (& iter );
214
+
215
+ if (key [0 ] != '$' ) {
216
+ return true;
217
+ }
218
+ }
219
+
220
+ return false;
221
+ }
222
+
223
+
224
+ /* true if there are $ and non-$ keys. precondition: bson must be valid. */
225
+ static bool
226
+ _mixed_dollar_non_dollar (const bson_t * bson )
227
+ {
228
+ return _has_dollar_fields (bson ) && _has_nondollar_fields (bson );
205
229
}
206
230
207
231
@@ -248,13 +272,19 @@ _mongoc_cursor_new_with_opts (mongoc_client_t *client,
248
272
}
249
273
250
274
if (opts ) {
251
- if (!bson_validate (opts ,
252
- BSON_VALIDATE_DOLLAR_KEYS | BSON_VALIDATE_EMPTY_KEYS ,
253
- NULL )) {
275
+ if (!bson_validate (opts , BSON_VALIDATE_EMPTY_KEYS , NULL )) {
276
+ MARK_FAILED (cursor );
277
+ bson_set_error (& cursor -> error , MONGOC_ERROR_CURSOR ,
278
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
279
+ "Cannot use empty keys in 'opts'." );
280
+ GOTO (finish );
281
+ }
282
+
283
+ if (_has_dollar_fields (opts )) {
254
284
MARK_FAILED (cursor );
255
285
bson_set_error (& cursor -> error , MONGOC_ERROR_CURSOR ,
256
286
MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
257
- "Cannot use $-modifiers or empty keys in 'opts'." );
287
+ "Cannot use $-modifiers in 'opts'." );
258
288
GOTO (finish );
259
289
}
260
290
0 commit comments