(self)
| 394 | assert 1500 < started[0].command["maxTimeMS"] <= 2000 |
| 395 | |
| 396 | def test_hint(self): |
| 397 | db = self.db |
| 398 | with self.assertRaises(TypeError): |
| 399 | db.test.find().hint(5.5) # type: ignore[arg-type] |
| 400 | db.test.drop() |
| 401 | |
| 402 | db.test.insert_many([{"num": i, "foo": i} for i in range(100)]) |
| 403 | |
| 404 | with self.assertRaises(OperationFailure): |
| 405 | db.test.find({"num": 17, "foo": 17}).hint([("num", ASCENDING)]).explain() |
| 406 | with self.assertRaises(OperationFailure): |
| 407 | db.test.find({"num": 17, "foo": 17}).hint([("foo", ASCENDING)]).explain() |
| 408 | |
| 409 | spec: list[Any] = [("num", DESCENDING)] |
| 410 | _ = db.test.create_index(spec) |
| 411 | |
| 412 | first = next(db.test.find()) |
| 413 | self.assertEqual(0, first.get("num")) |
| 414 | first = next(db.test.find().hint(spec)) |
| 415 | self.assertEqual(99, first.get("num")) |
| 416 | with self.assertRaises(OperationFailure): |
| 417 | db.test.find({"num": 17, "foo": 17}).hint([("foo", ASCENDING)]).explain() |
| 418 | |
| 419 | a = db.test.find({"num": 17}) |
| 420 | a.hint(spec) |
| 421 | for _ in a: |
| 422 | break |
| 423 | self.assertRaises(InvalidOperation, a.hint, spec) |
| 424 | |
| 425 | db.test.drop() |
| 426 | db.test.insert_many([{"num": i, "foo": i} for i in range(100)]) |
| 427 | spec: _IndexList = ["num", ("foo", DESCENDING)] |
| 428 | db.test.create_index(spec) |
| 429 | first = next(db.test.find().hint(spec)) |
| 430 | self.assertEqual(0, first.get("num")) |
| 431 | self.assertEqual(0, first.get("foo")) |
| 432 | |
| 433 | db.test.drop() |
| 434 | db.test.insert_many([{"num": i, "foo": i} for i in range(100)]) |
| 435 | spec = ["num"] |
| 436 | db.test.create_index(spec) |
| 437 | first = next(db.test.find().hint(spec)) |
| 438 | self.assertEqual(0, first.get("num")) |
| 439 | |
| 440 | def test_hint_by_name(self): |
| 441 | db = self.db |
nothing calls this directly
no test coverage detected