<s> from Mojo . Backends . base_interface import CollectionModelInterface , SessionInterface <EOL> import pymongo <EOL> import logging <EOL> class Session ( SessionInterface ) : <EOL> def _setup_connection ( self ) : <EOL> self . _db = pymongo . Connection ( <EOL> host = self . host , <EOL> port = self . port , <EOL> ) [ self . db_name ] <EOL> class Collection ( CollectionModelInterface ) : <EOL> def find_one ( self , * args , ** kwargs ) : <EOL> return_dict = self . session . _db [ self . collection_name ] . find_one ( * args , ** kwargs ) <EOL> return self . _return_model_object ( return_dict ) <EOL> def find ( self , * args , ** kwargs ) : <EOL> return_cursor = self . session . _db [ self . collection_name ] . find ( * args , ** kwargs ) <EOL> return_model_list = [ self . _return_model_object ( i ) for i in return_cursor ] <EOL> return return_model_list <EOL> def insert ( self , documents , * args , ** kwargs ) : <EOL> ret_vals = [ ] <EOL> if type ( documents ) != list : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> insert_list = [ ] <EOL> for doc in documents : <EOL> del doc [ '<STR_LIT>' ] <EOL> insert_list . append ( doc . get_value ( ) ) <EOL> ids = self . session . _db [ self . collection_name ] . insert ( insert_list ) <EOL> index = <NUM_LIT:0> <EOL> for doc in documents : <EOL> doc [ '<STR_LIT>' ] = ids [ index ] <EOL> index += <NUM_LIT:1> <EOL> ret_vals . append ( doc ) <EOL> return ret_vals <EOL> def save ( self , document , * args , ** kwargs ) : <EOL> temp_doc = dict ( document ) <EOL> if not document . _id : <EOL> del temp_doc [ '<STR_LIT>' ] <EOL> returnID = self . session . _db [ self . collection_name ] . save ( temp_doc , * args , ** kwargs ) <EOL> document . _id = returnID <EOL> return document <EOL> def delete ( self , documents , * args , ** kwargs ) : <EOL> return_values = [ ] <EOL> for document in documents : <EOL> ret_val = self . session . _db [ self . collection_name ] . remove ( document . _id ) <EOL> return_values . append ( ret_val ) <EOL> return return_values </s>
