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