Transferring between accounts – part 3

The correct implementation to the transfer problem will look like the following code (the full code sample is attached with the code bundle):

from pymongo import MongoClientimport jsonclass InitData:   def __init__(self):       self.client = MongoClient('localhost', 27017, w='majority')       self.db = self.client.mongo_bank       self.accounts = self.db.accounts       # drop data from accounts collection every time to start from a clean slate       self.accounts.drop()       init_data = InitData.load_data(self)       self.insert_data(init_data)       self.transfer('1', '2', 300)   @staticmethod   def load_data(self):       ret = []       with open('init_data.json', 'r') as f:           for line in f:               ret.append(json.loads(line))       return ret   def insert_data(self, data): for document ...

Get Mastering MongoDB 4.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.