def validate_insert_fields(fields):
    """Validate field names for insertion.

       :param fields: a list of field names

       :returns: None
    """
    for f in fields:
        if f.endswith('.'):
            raise ValueError("invalid fieldname: %r, must not end in '.'" % f)
        if '$' in f:
            raise ValueError("invalid fieldname: %r, must not contain '$'" % f)
    if len(fields) != len(set(fields)):
        raise ValueError('field names must all be unique')
    for f1 in fields:
        for f2 in fields:
            if f1 != f2 and f1.startswith(f2) and f1[len(f2)] == '.':
                raise ValueError(
                    'fieldname %r conflicts with nested-document fieldname %r'
                     % (f2, f1))
