'Return as SON data ready for use with MongoDB.'

def to_mongo(self, use_db_field=True, fields=None):

    if (not fields):
        fields = []
    data = SON()
    data['_id'] = None
    data['_cls'] = self._class_name
    root_fields = set([f.split('.')[0] for f in fields])
    for field_name in self:
        if (root_fields and (field_name not in root_fields)):
            continue
        value = self._data.get(field_name, None)
        field = self._fields.get(field_name)
        if ((field is None) and self._dynamic):
            field = self._dynamic_fields.get(field_name)
        if (value is not None):
            f_inputs = field.to_mongo.__code__.co_varnames
            ex_vars = {}
            if (fields and ('fields' in f_inputs)):
                key = ('%s.' % field_name)
                embedded_fields = [i.replace(key, '') for i in fields if i.startswith(key)]
                ex_vars['fields'] = embedded_fields
            if ('use_db_field' in f_inputs):
                ex_vars['use_db_field'] = use_db_field
            value = field.to_mongo(value, **ex_vars)
        if ((value is None) and field._auto_gen):
            value = field.generate()
            self._data[field_name] = value
        if (value is not None):
            if use_db_field:
                data[field.db_field] = value
            else:
                data[field.name] = value
    if (not self._meta.get('allow_inheritance')):
        data.pop('_cls')
    return data
