MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_min

Method test_min

test/test_cursor.py:541–578  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

539 db.test.find().max({"j": 10}) # type: ignore[arg-type]
540
541 def test_min(self):
542 db = self.db
543 db.test.drop()
544 j_index = [("j", ASCENDING)]
545 db.test.create_index(j_index)
546
547 db.test.insert_many([{"j": j, "k": j} for j in range(10)])
548
549 def find(min_spec, expected_index):
550 return db.test.find().min(min_spec).hint(expected_index)
551
552 cursor = find([("j", 3)], j_index)
553 self.assertEqual(len(cursor.to_list()), 7)
554
555 # Tuple.
556 cursor = find((("j", 3),), j_index)
557 self.assertEqual(len(cursor.to_list()), 7)
558
559 # Compound index.
560 index_keys = [("j", ASCENDING), ("k", ASCENDING)]
561 db.test.create_index(index_keys)
562 cursor = find([("j", 3), ("k", 3)], index_keys)
563 self.assertEqual(len(cursor.to_list()), 7)
564
565 # Wrong order.
566 cursor = find([("k", 3), ("j", 3)], index_keys)
567 with self.assertRaises(OperationFailure):
568 cursor.to_list()
569
570 # No such index.
571 cursor = find([("k", 3)], "k")
572 with self.assertRaises(OperationFailure):
573 cursor.to_list()
574
575 with self.assertRaises(TypeError):
576 db.test.find().min(10) # type: ignore[arg-type]
577 with self.assertRaises(TypeError):
578 db.test.find().min({"j": 10}) # type: ignore[arg-type]
579
580 def test_min_max_without_hint(self):
581 coll = self.db.test

Callers

nothing calls this directly

Calls 6

dropMethod · 0.45
create_indexMethod · 0.45
insert_manyMethod · 0.45
to_listMethod · 0.45
minMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected