@@ -69,7 +69,7 @@ class ImplicitMovie(TypedDict):
6969
7070from test import IntegrationTest , PyMongoTestCase , client_context
7171
72- from bson import CodecOptions , decode , decode_all , decode_file_iter , decode_iter , encode
72+ from bson import CodecOptions , ObjectId , decode , decode_all , decode_file_iter , decode_iter , encode
7373from bson .raw_bson import RawBSONDocument
7474from bson .son import SON
7575from pymongo import ASCENDING , MongoClient
@@ -141,6 +141,32 @@ def to_list(iterable: Iterable[Dict[str, Any]]) -> List[Dict[str, Any]]:
141141 docs = to_list (cursor )
142142 self .assertTrue (docs )
143143
144+ def test_distinct (self ) -> None :
145+ self .coll .delete_many ({})
146+ self .coll .insert_many (
147+ [
148+ {"_id" : None },
149+ {"_id" : 0 },
150+ {"_id" : "" },
151+ {"_id" : ObjectId ()},
152+ {"_id" : True },
153+ ]
154+ )
155+
156+ def collection_distinct (
157+ collection : Collection ,
158+ ) -> list [None | int | str | ObjectId | bool ]:
159+ return collection .distinct ("_id" )
160+
161+ def cursor_distinct (
162+ collection : Collection ,
163+ ) -> list [None | int | str | ObjectId | bool ]:
164+ cursor = collection .find ()
165+ return cursor .distinct ("_id" )
166+
167+ collection_distinct (self .coll )
168+ cursor_distinct (self .coll )
169+
144170 @only_type_check
145171 def test_bulk_write (self ) -> None :
146172 self .coll .insert_one ({})
0 commit comments