def store_plan(self, plan): plan.validate() d = plan.to_dict() d["_id"] = d["name"] del d["name"] try: self.db[self.plans_collection].insert(d) except pymongo.errors.DuplicateKeyError: raise DuplicateError(plan.name)