<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_aggregation(self, course, aggregationid, new_data):
 """ Update aggregation and returns a list of errored students"""


        student_list = self.user_manager.get_course_registered_users(course, False)

        # If aggregation is new
        if aggregationid == 'None':
            # Remove _id for correct insertion
            del new_data['_id']
            new_data["courseid"] = course.get_id()

            # Insert the new aggregation
            result = self.database.aggregations.insert_one(new_data)

            # Retrieve new aggregation id
            aggregationid = result.inserted_id
            new_data['_id'] = result.inserted_id
            aggregation = new_data
        else:
            aggregation = self.database.aggregations.find_one({"_id": ObjectId(aggregationid), "courseid": course.get_id()})

        # Check tutors
        new_data["tutors"] = [tutor for tutor in new_data["tutors"] if tutor in course.get_staff()]

        students, groups, errored_students = [], [], []

        # Check the students
        for student in new_data["students"]:
            if student in student_list:
                # Remove user from the other aggregation
                self.database.aggregations.find_one_and_update({"courseid": course.get_id(), "groups.students": student},
                                                             {"$pull": {"groups.$.students": student, "students": student}})
                self.database.aggregations.find_one_and_update({"courseid": course.get_id(), "students": student}, {"$pull": {"students": student}})
                students.append(student)
            else:
                # Check if user can be registered
                user_info = self.user_manager.get_user_info(student)
                if user_info is None or student in aggregation["tutors"]:
                    errored_students.append(student)
                else:
                    students.append(student)

        removed_students = [student for student in aggregation["students"] if student not in new_data["students"]]
        self.database.aggregations.find_one_and_update({"courseid": course.get_id(), "default": True},
                                                     {"$push": {"students": {"$each": removed_students}}})

        new_data["students"] = students

        # Check the groups
        for group in new_data["groups"]:
            group["students"] = [student for student in group["students"] if student in new_data["students"]]
            if len(group["students"]) <= group["size"]:
                groups.append(group)

        new_data["groups"] = groups

        # Check for default aggregation
        if new_data['default']:
            self.database.aggregations.find_one_and_update({"courseid": course.get_id(), "default": True},
                                                         {"$set": {"default": False}})

        aggregation = self.database.aggregations.find_one_and_update(
            {"_id": ObjectId(aggregationid)},
            {"$set": {"description": new_data["description"],
                      "students": students, "tutors": new_data["tutors"],
                      "groups": groups, "default": new_data['default']}}, return_document=ReturnDocument.AFTER)

        return aggregation, errored_students