@@ -44,7 +44,7 @@ async def list(self, request):
4444 .sort (paging .sort_field , sort_direction ))
4545
4646 entities = await cursor .to_list (paging .limit )
47- count = await self ._collection .find (query ). count ( )
47+ count = await self ._collection .count_documents (query )
4848 headers = {'X-Total-Count' : str (count )}
4949 return json_response (entities , headers = headers )
5050
@@ -66,8 +66,8 @@ async def create(self, request):
6666 raw_payload = await request .read ()
6767 data = validate_payload (raw_payload , self ._update_schema )
6868
69- entity_id = await self ._collection .insert (data )
70- query = {self ._primary_key : ObjectId ( entity_id ) }
69+ result = await self ._collection .insert_one (data )
70+ query = {self ._primary_key : result . inserted_id }
7171 doc = await self ._collection .find_one (query )
7272
7373 return json_response (doc )
@@ -79,7 +79,7 @@ async def update(self, request):
7979 data = validate_payload (raw_payload , self ._update_schema )
8080 query = {self ._primary_key : ObjectId (entity_id )}
8181
82- doc = await self ._collection .find_and_modify (
82+ doc = await self ._collection .find_one_and_update (
8383 query , {"$set" : data }, upsert = False , new = True )
8484
8585 if not doc :
@@ -93,5 +93,5 @@ async def delete(self, request):
9393 entity_id = request .match_info ['entity_id' ]
9494 # TODO: fix ObjectId is not always valid case
9595 query = {self ._primary_key : ObjectId (entity_id )}
96- await self ._collection .remove (query )
96+ await self ._collection .delete_one (query )
9797 return json_response ({'status' : 'deleted' })
0 commit comments