1313# limitations under the License.
1414
1515"""Collection level utilities for Mongo."""
16+ from __future__ import annotations
1617
1718from collections import abc
1819from typing import (
@@ -114,14 +115,14 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
114115
115116 def __init__ (
116117 self ,
117- database : " Database[_DocumentType]" ,
118+ database : Database [_DocumentType ],
118119 name : str ,
119120 create : Optional [bool ] = False ,
120- codec_options : Optional [" CodecOptions[_DocumentTypeArg]" ] = None ,
121+ codec_options : Optional [CodecOptions [_DocumentTypeArg ]] = None ,
121122 read_preference : Optional [_ServerMode ] = None ,
122123 write_concern : Optional [WriteConcern ] = None ,
123- read_concern : Optional [" ReadConcern" ] = None ,
124- session : Optional [" ClientSession" ] = None ,
124+ read_concern : Optional [ReadConcern ] = None ,
125+ session : Optional [ClientSession ] = None ,
125126 ** kwargs : Any ,
126127 ) -> None :
127128 """Get / create a Mongo collection.
@@ -335,7 +336,7 @@ def __create(
335336 session = session ,
336337 )
337338
338- def __getattr__ (self , name : str ) -> " Collection[_DocumentType]" :
339+ def __getattr__ (self , name : str ) -> Collection [_DocumentType ]:
339340 """Get a sub-collection of this collection by name.
340341
341342 Raises InvalidName if an invalid collection name is used.
@@ -351,7 +352,7 @@ def __getattr__(self, name: str) -> "Collection[_DocumentType]":
351352 )
352353 return self .__getitem__ (name )
353354
354- def __getitem__ (self , name : str ) -> " Collection[_DocumentType]" :
355+ def __getitem__ (self , name : str ) -> Collection [_DocumentType ]:
355356 return Collection (
356357 self .__database ,
357358 f"{ self .__name } .{ name } " ,
@@ -397,19 +398,19 @@ def name(self) -> str:
397398 return self .__name
398399
399400 @property
400- def database (self ) -> " Database[_DocumentType]" :
401+ def database (self ) -> Database [_DocumentType ]:
401402 """The :class:`~pymongo.database.Database` that this
402403 :class:`Collection` is a part of.
403404 """
404405 return self .__database
405406
406407 def with_options (
407408 self ,
408- codec_options : Optional [" bson.CodecOptions[_DocumentTypeArg]" ] = None ,
409+ codec_options : Optional [bson .CodecOptions [_DocumentTypeArg ]] = None ,
409410 read_preference : Optional [_ServerMode ] = None ,
410411 write_concern : Optional [WriteConcern ] = None ,
411- read_concern : Optional [" ReadConcern" ] = None ,
412- ) -> " Collection[_DocumentType]" :
412+ read_concern : Optional [ReadConcern ] = None ,
413+ ) -> Collection [_DocumentType ]:
413414 """Get a clone of this collection changing the specified settings.
414415
415416 >>> coll1.read_preference
@@ -455,7 +456,7 @@ def bulk_write(
455456 requests : Sequence [_WriteOp [_DocumentType ]],
456457 ordered : bool = True ,
457458 bypass_document_validation : bool = False ,
458- session : Optional [" ClientSession" ] = None ,
459+ session : Optional [ClientSession ] = None ,
459460 comment : Optional [Any ] = None ,
460461 let : Optional [Mapping ] = None ,
461462 ) -> BulkWriteResult :
@@ -585,7 +586,7 @@ def insert_one(
585586 self ,
586587 document : Union [_DocumentType , RawBSONDocument ],
587588 bypass_document_validation : bool = False ,
588- session : Optional [" ClientSession" ] = None ,
589+ session : Optional [ClientSession ] = None ,
589590 comment : Optional [Any ] = None ,
590591 ) -> InsertOneResult :
591592 """Insert a single document.
@@ -653,7 +654,7 @@ def insert_many(
653654 documents : Iterable [Union [_DocumentType , RawBSONDocument ]],
654655 ordered : bool = True ,
655656 bypass_document_validation : bool = False ,
656- session : Optional [" ClientSession" ] = None ,
657+ session : Optional [ClientSession ] = None ,
657658 comment : Optional [Any ] = None ,
658659 ) -> InsertManyResult :
659660 """Insert an iterable of documents.
@@ -855,7 +856,7 @@ def replace_one(
855856 bypass_document_validation : bool = False ,
856857 collation : Optional [_CollationIn ] = None ,
857858 hint : Optional [_IndexKeyHint ] = None ,
858- session : Optional [" ClientSession" ] = None ,
859+ session : Optional [ClientSession ] = None ,
859860 let : Optional [Mapping [str , Any ]] = None ,
860861 comment : Optional [Any ] = None ,
861862 ) -> UpdateResult :
@@ -959,7 +960,7 @@ def update_one(
959960 collation : Optional [_CollationIn ] = None ,
960961 array_filters : Optional [Sequence [Mapping [str , Any ]]] = None ,
961962 hint : Optional [_IndexKeyHint ] = None ,
962- session : Optional [" ClientSession" ] = None ,
963+ session : Optional [ClientSession ] = None ,
963964 let : Optional [Mapping [str , Any ]] = None ,
964965 comment : Optional [Any ] = None ,
965966 ) -> UpdateResult :
@@ -1073,7 +1074,7 @@ def update_many(
10731074 bypass_document_validation : Optional [bool ] = None ,
10741075 collation : Optional [_CollationIn ] = None ,
10751076 hint : Optional [_IndexKeyHint ] = None ,
1076- session : Optional [" ClientSession" ] = None ,
1077+ session : Optional [ClientSession ] = None ,
10771078 let : Optional [Mapping [str , Any ]] = None ,
10781079 comment : Optional [Any ] = None ,
10791080 ) -> UpdateResult :
@@ -1168,7 +1169,7 @@ def update_many(
11681169
11691170 def drop (
11701171 self ,
1171- session : Optional [" ClientSession" ] = None ,
1172+ session : Optional [ClientSession ] = None ,
11721173 comment : Optional [Any ] = None ,
11731174 encrypted_fields : Optional [Mapping [str , Any ]] = None ,
11741175 ) -> None :
@@ -1306,7 +1307,7 @@ def delete_one(
13061307 filter : Mapping [str , Any ],
13071308 collation : Optional [_CollationIn ] = None ,
13081309 hint : Optional [_IndexKeyHint ] = None ,
1309- session : Optional [" ClientSession" ] = None ,
1310+ session : Optional [ClientSession ] = None ,
13101311 let : Optional [Mapping [str , Any ]] = None ,
13111312 comment : Optional [Any ] = None ,
13121313 ) -> DeleteResult :
@@ -1373,7 +1374,7 @@ def delete_many(
13731374 filter : Mapping [str , Any ],
13741375 collation : Optional [_CollationIn ] = None ,
13751376 hint : Optional [_IndexKeyHint ] = None ,
1376- session : Optional [" ClientSession" ] = None ,
1377+ session : Optional [ClientSession ] = None ,
13771378 let : Optional [Mapping [str , Any ]] = None ,
13781379 comment : Optional [Any ] = None ,
13791380 ) -> DeleteResult :
@@ -1769,7 +1770,7 @@ def _cmd(session, server, sock_info, read_preference):
17691770 def count_documents (
17701771 self ,
17711772 filter : Mapping [str , Any ],
1772- session : Optional [" ClientSession" ] = None ,
1773+ session : Optional [ClientSession ] = None ,
17731774 comment : Optional [Any ] = None ,
17741775 ** kwargs : Any ,
17751776 ) -> int :
@@ -1860,7 +1861,7 @@ def _retryable_non_cursor_read(self, func, session):
18601861 def create_indexes (
18611862 self ,
18621863 indexes : Sequence [IndexModel ],
1863- session : Optional [" ClientSession" ] = None ,
1864+ session : Optional [ClientSession ] = None ,
18641865 comment : Optional [Any ] = None ,
18651866 ** kwargs : Any ,
18661867 ) -> List [str ]:
@@ -1952,7 +1953,7 @@ def gen_indexes():
19521953 def create_index (
19531954 self ,
19541955 keys : _IndexKeyHint ,
1955- session : Optional [" ClientSession" ] = None ,
1956+ session : Optional [ClientSession ] = None ,
19561957 comment : Optional [Any ] = None ,
19571958 ** kwargs : Any ,
19581959 ) -> str :
@@ -2071,7 +2072,7 @@ def create_index(
20712072
20722073 def drop_indexes (
20732074 self ,
2074- session : Optional [" ClientSession" ] = None ,
2075+ session : Optional [ClientSession ] = None ,
20752076 comment : Optional [Any ] = None ,
20762077 ** kwargs : Any ,
20772078 ) -> None :
@@ -2107,7 +2108,7 @@ def drop_indexes(
21072108 def drop_index (
21082109 self ,
21092110 index_or_name : _IndexKeyHint ,
2110- session : Optional [" ClientSession" ] = None ,
2111+ session : Optional [ClientSession ] = None ,
21112112 comment : Optional [Any ] = None ,
21122113 ** kwargs : Any ,
21132114 ) -> None :
@@ -2174,7 +2175,7 @@ def drop_index(
21742175
21752176 def list_indexes (
21762177 self ,
2177- session : Optional [" ClientSession" ] = None ,
2178+ session : Optional [ClientSession ] = None ,
21782179 comment : Optional [Any ] = None ,
21792180 ) -> CommandCursor [MutableMapping [str , Any ]]:
21802181 """Get a cursor over the index documents for this collection.
@@ -2239,7 +2240,7 @@ def _cmd(session, server, sock_info, read_preference):
22392240
22402241 def index_information (
22412242 self ,
2242- session : Optional [" ClientSession" ] = None ,
2243+ session : Optional [ClientSession ] = None ,
22432244 comment : Optional [Any ] = None ,
22442245 ) -> MutableMapping [str , Any ]:
22452246 """Get information on this collection's indexes.
@@ -2282,7 +2283,7 @@ def index_information(
22822283
22832284 def options (
22842285 self ,
2285- session : Optional [" ClientSession" ] = None ,
2286+ session : Optional [ClientSession ] = None ,
22862287 comment : Optional [Any ] = None ,
22872288 ) -> MutableMapping [str , Any ]:
22882289 """Get the options set on this collection.
@@ -2361,7 +2362,7 @@ def _aggregate(
23612362 def aggregate (
23622363 self ,
23632364 pipeline : _Pipeline ,
2364- session : Optional [" ClientSession" ] = None ,
2365+ session : Optional [ClientSession ] = None ,
23652366 let : Optional [Mapping [str , Any ]] = None ,
23662367 comment : Optional [Any ] = None ,
23672368 ** kwargs : Any ,
@@ -2458,7 +2459,7 @@ def aggregate(
24582459 def aggregate_raw_batches (
24592460 self ,
24602461 pipeline : _Pipeline ,
2461- session : Optional [" ClientSession" ] = None ,
2462+ session : Optional [ClientSession ] = None ,
24622463 comment : Optional [Any ] = None ,
24632464 ** kwargs : Any ,
24642465 ) -> RawBatchCursor [_DocumentType ]:
@@ -2509,7 +2510,7 @@ def watch(
25092510 batch_size : Optional [int ] = None ,
25102511 collation : Optional [_CollationIn ] = None ,
25112512 start_at_operation_time : Optional [Timestamp ] = None ,
2512- session : Optional [" ClientSession" ] = None ,
2513+ session : Optional [ClientSession ] = None ,
25132514 start_after : Optional [Mapping [str , Any ]] = None ,
25142515 comment : Optional [Any ] = None ,
25152516 full_document_before_change : Optional [str ] = None ,
@@ -2644,7 +2645,7 @@ def watch(
26442645 def rename (
26452646 self ,
26462647 new_name : str ,
2647- session : Optional [" ClientSession" ] = None ,
2648+ session : Optional [ClientSession ] = None ,
26482649 comment : Optional [Any ] = None ,
26492650 ** kwargs : Any ,
26502651 ) -> MutableMapping [str , Any ]:
@@ -2709,7 +2710,7 @@ def distinct(
27092710 self ,
27102711 key : str ,
27112712 filter : Optional [Mapping [str , Any ]] = None ,
2712- session : Optional [" ClientSession" ] = None ,
2713+ session : Optional [ClientSession ] = None ,
27132714 comment : Optional [Any ] = None ,
27142715 ** kwargs : Any ,
27152716 ) -> List :
@@ -2860,7 +2861,7 @@ def find_one_and_delete(
28602861 projection : Optional [Union [Mapping [str , Any ], Iterable [str ]]] = None ,
28612862 sort : Optional [_IndexList ] = None ,
28622863 hint : Optional [_IndexKeyHint ] = None ,
2863- session : Optional [" ClientSession" ] = None ,
2864+ session : Optional [ClientSession ] = None ,
28642865 let : Optional [Mapping [str , Any ]] = None ,
28652866 comment : Optional [Any ] = None ,
28662867 ** kwargs : Any ,
@@ -2953,7 +2954,7 @@ def find_one_and_replace(
29532954 upsert : bool = False ,
29542955 return_document : bool = ReturnDocument .BEFORE ,
29552956 hint : Optional [_IndexKeyHint ] = None ,
2956- session : Optional [" ClientSession" ] = None ,
2957+ session : Optional [ClientSession ] = None ,
29572958 let : Optional [Mapping [str , Any ]] = None ,
29582959 comment : Optional [Any ] = None ,
29592960 ** kwargs : Any ,
@@ -3062,7 +3063,7 @@ def find_one_and_update(
30623063 return_document : bool = ReturnDocument .BEFORE ,
30633064 array_filters : Optional [Sequence [Mapping [str , Any ]]] = None ,
30643065 hint : Optional [_IndexKeyHint ] = None ,
3065- session : Optional [" ClientSession" ] = None ,
3066+ session : Optional [ClientSession ] = None ,
30663067 let : Optional [Mapping [str , Any ]] = None ,
30673068 comment : Optional [Any ] = None ,
30683069 ** kwargs : Any ,
0 commit comments