44from pymongo .cursor import Cursor
55from pymongo .results import InsertOneResult , DeleteResult , UpdateResult
66
7- from fastapi_contrib .db .models import MongoDBModel
7+ from fastapi_contrib .db .models import MongoDBModel , notset
88from fastapi_contrib .common .utils import get_current_app , get_timezone
99
1010
@@ -50,8 +50,8 @@ async def insert(
5050 async def count (
5151 self , model : MongoDBModel , session : ClientSession = None , ** kwargs
5252 ) -> int :
53- _id = kwargs .pop ("id" , None )
54- if _id is not None :
53+ _id = kwargs .pop ("id" , notset )
54+ if _id != notset :
5555 kwargs ["_id" ] = _id
5656
5757 collection_name = model .get_db_collection ()
@@ -62,8 +62,8 @@ async def count(
6262 async def delete (
6363 self , model : MongoDBModel , session : ClientSession = None , ** kwargs
6464 ) -> DeleteResult :
65- _id = kwargs .pop ("id" , None )
66- if _id is not None :
65+ _id = kwargs .pop ("id" , notset )
66+ if _id != notset :
6767 kwargs ["_id" ] = _id
6868
6969 collection_name = model .get_db_collection ()
@@ -78,8 +78,8 @@ async def update_one(
7878 session : ClientSession = None ,
7979 ** kwargs
8080 ) -> UpdateResult :
81- _id = filter_kwargs .pop ("id" , None )
82- if _id is not None :
81+ _id = filter_kwargs .pop ("id" , notset )
82+ if _id != notset :
8383 filter_kwargs ["_id" ] = _id
8484
8585 collection_name = model .get_db_collection ()
@@ -96,8 +96,8 @@ async def update_many(
9696 session : ClientSession = None ,
9797 ** kwargs
9898 ) -> UpdateResult :
99- _id = filter_kwargs .pop ("id" , None )
100- if _id is not None :
99+ _id = filter_kwargs .pop ("id" , notset )
100+ if _id != notset :
101101 filter_kwargs ["_id" ] = _id
102102
103103 collection_name = model .get_db_collection ()
@@ -110,8 +110,8 @@ async def update_many(
110110 async def get (
111111 self , model : MongoDBModel , session : ClientSession = None , ** kwargs
112112 ) -> dict :
113- _id = kwargs .pop ("id" , None )
114- if _id is not None :
113+ _id = kwargs .pop ("id" , notset )
114+ if _id != notset :
115115 kwargs ["_id" ] = _id
116116
117117 collection_name = model .get_db_collection ()
@@ -128,8 +128,8 @@ def list(
128128 _sort : list = None ,
129129 ** kwargs
130130 ) -> Cursor :
131- _id = kwargs .pop ("id" , None )
132- if _id is not None :
131+ _id = kwargs .pop ("id" , notset )
132+ if _id != notset :
133133 kwargs ["_id" ] = _id
134134
135135 collection_name = model .get_db_collection ()
0 commit comments