def _add_group_id_fields(self, out_collection, group_func_keys):
        date_operators = [
            'dayOfYear',
            'dayOfMonth',
            'dayOfWeek',
            'year',
            'month',
            'week',
            'hour',
            'minute',
            'second',
            'millisecond']

        clear_group_func_keys = []
        for key in group_func_keys:
            out_field = key.split('__')[0]

            for doc in out_collection:
                if key not in doc.keys():
                    func_field = key.split('__')[1]
                    func, in_field = func_field.split('_')
                    out_value = doc.get(in_field)

                    if func in date_operators:
                        if func == 'dayOfYear':
                            out_value = out_value.timetuple().tm_yday
                        elif func == 'dayOfMonth':
                            out_value = out_value.day
                        elif func == 'dayOfWeek':
                            out_value = out_value.isoweekday()
                        elif func == 'year':
                            out_value = out_value.year
                        elif func == 'month':
                            out_value = out_value.month
                        elif func == 'week':
                            out_value = out_value.isocalendar()[1]
                        elif func == 'hour':
                            out_value = out_value.hour
                        elif func == 'minute':
                            out_value = out_value.minute
                        elif func == 'second':
                            out_value = out_value.second
                        elif func == 'millisecond':
                            out_value = int(out_value.microsecond / 1000)

                    doc[out_field] = out_value

            clear_group_func_keys.append(out_field)

        return out_collection, clear_group_func_keys
dataset/ETHPy150Open vmalloc/mongomock/mongomock/collection.py/Collection._add_group_id_fields/original