<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_case(self, case, update=False):
 """Add a case to the case collection If the case exists and update is False raise error. Args: db (MongoClient):
 A connection to the mongodb case (dict):
 A case dictionary update(bool):
 If existing case should be updated Returns: mongo_case_id(ObjectId) """

        existing_case = self.case(case)
        if existing_case and not update:
            raise CaseError("Case {} already exists".format(case['case_id']))
        if existing_case:
            self.db.case.find_one_and_replace(
                {'case_id': case['case_id']},
                case,
            )
        else:
            self.db.case.insert_one(case)

        return case