@@ -69,7 +69,7 @@ class ImplicitMovie(TypedDict):
69
69
70
70
from test import IntegrationTest , PyMongoTestCase , client_context
71
71
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
73
73
from bson .raw_bson import RawBSONDocument
74
74
from bson .son import SON
75
75
from pymongo import ASCENDING , MongoClient
@@ -141,6 +141,32 @@ def to_list(iterable: Iterable[Dict[str, Any]]) -> List[Dict[str, Any]]:
141
141
docs = to_list (cursor )
142
142
self .assertTrue (docs )
143
143
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
+
144
170
@only_type_check
145
171
def test_bulk_write (self ) -> None :
146
172
self .coll .insert_one ({})
0 commit comments